Home » Archived » Lua Development Tools » Autocompletion for external API
Autocompletion for external API [message #1168304] |
Sun, 03 November 2013 02:28  |
Eclipse User |
|
|
|
Hi there,
Let's say I want to add documentation to an external dynamic library such as LFS, in order to get a autocomplete feature over these function. Right now, I'm pretty sure it's impossible to link a source package like it can be done in java, since usually these external library that aren't .lua are wrote in C.
So, if the programmer really want to get autocompletion for this, he can either try to:
-Create a class with documentation that somehow "mock/mimic" the external library(but when running the program, he switch to the real library).
-Create somekind of an adapter class with documentation where he simply recall the original library for each field and function.
So far, I guess that Koneki has probably some other priorities, but I was wondering if there could be something to be done here.
I mean, once we use the "require" statement for an external library, it's possible to detect a new table/module on _G. Then, it's usually possible to detect wether the "top element" inside the said component is a function/variable/userdata with his related name. Here's a piece of code that show what I mean(borrowed from TableSerialization : "Universal tostring"):
function table_print (tt, indent, done)
done = done or {}
indent = indent or 0
if type(tt) == "table" then
local sb = {}
for key, value in pairs (tt) do
table.insert(sb, string.rep (" ", indent)) -- indent it
if type (value) == "table" and not done [value] then
done [value] = true
table.insert(sb, "{\n");
table.insert(sb, table_print (value, indent + 2, done))
table.insert(sb, string.rep (" ", indent)) -- indent it
table.insert(sb, "}\n");
elseif "number" == type(key) then
table.insert(sb, string.format("\"%s\"\n", tostring(value)))
else
table.insert(sb, string.format(
"%s = \"%s\"\n", tostring (key), tostring(value)))
end
end
return table.concat(sb)
else
return tt .. "\n"
end
end
function to_string( tbl )
if "nil" == type( tbl ) then
return tostring(nil)
elseif "table" == type( tbl ) then
return table_print(tbl)
elseif "string" == type( tbl ) then
return tbl
else
return tostring(tbl)
end
end
Then we can do something like
require "lfs"
print(to_string(lfs))
While this isn't the best implementation, the only downside is that we don't know the suggested parameter for a function.
So my question, would it be possible to add autocomplete for a dynamic library(.dll on windows or .so on unix)?
Thanks again,
Btw, I've compilled 1.1_M2 with maven3 for testing this issue and it seem to work great now, as long as we respect the luadoc nomenclature
[Updated on: Sun, 03 November 2013 15:48] by Moderator
|
|
| | |
Re: Autocompletion for external API [message #1203336 is a reply to message #1173686] |
Fri, 22 November 2013 10:56   |
Eclipse User |
|
|
|
Simon Bernard wrote on Wed, 06 November 2013 12:42A solution for your problem, could be to create a mock file with the API written with the documentation language, to package it in a zip file and to add it to the sourcepath/buildpath
(right on your project/ Build Path / add External Archives)
In this case, the file will be not used at runtime and you don't need to implement adapter or to switch manualy.
In Koneki 1.1_M2, I could go in build path > source > Add Folder and this new folder path could be used as source for the autocompletion when using require statement. No need to zip those(which is very useful, so I can add these external API on the go, without zipping/unzipping for every change). Also, at the time, the buildpath wasn't added in package.path variable.
Now I recently made a check out Koneki of the "master" branch(last commit is 4854af99e64e3ddd1c77920a482f89e660fcb198 ) and all theses path from the buildpath are added in package.path variable when I execute a lua script. I didn't find a way to exclude those path theses "folder variable" or to uncheck them in "Order and Export". Before, I thought we had to go in Preferences > Lua Interpreters > Edit in order to add customize path. That's why I got a bit confuse
Furthermore, in "Libaries" > "Add Library..." > "Lua User Libraries", I get the following exception:
Plug-in org.eclipse.koneki.ldt.ui was unable to load class org.eclipse.dltk.internal.ui.internal.wizards.buildpath.UserLibraryWizardPage.
org.eclipse.dltk.internal.ui.internal.wizards.buildpath.UserLibraryWizardPage cannot be found by org.eclipse.koneki.ldt.ui_1.1.0.201311012011
That said, I can still work around these issue without problem, so nothing be stressed about either, I just wanted to let you know about this 
Also, I tested if reference works between modules and now it work pretty good!
[Updated on: Fri, 22 November 2013 12:35] by Moderator
|
|
| | |
Re: Autocompletion for external API [message #1216255 is a reply to message #1214437] |
Thu, 28 November 2013 06:43  |
Eclipse User |
|
|
|
In fact, its possible to use any transport layer for debugging. But you need to implement a specific layer abstraction.
To implement your own transport interface based on your own library (see the interface and the transport parameter)
(We probably need more documentation on that :/)
We currently provide by default the luasocket implementation because we think that luasocket is the most popular library for socket in lua.
You could try to make an implementation for ZMQ. We could make a wiki page to reference all the transport layer implementation for LDT as we do for execution environment.(and so reference your ZMQ implementation and maybe one day we could integrate it directly in LDT)
|
|
|
Goto Forum:
Current Time: Wed Mar 19 18:57:10 EDT 2025
Powered by FUDForum. Page generated in 0.03976 seconds
|