Home » Archived » Lua Development Tools » Autocompletion for external API
Autocompletion for external API [message #1168304] |
Sun, 03 November 2013 07:28 |
|
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 20:48] Report message to a moderator
|
|
| |
Re: Autocompletion for external API [message #1184321 is a reply to message #1168304] |
Wed, 13 November 2013 11:16 |
|
Thanks, writing the mock API is a bit more work but it's actually worth it!
Also, since there's already an api.zip for storing the global lua function/value, which come with koneki* it look like that this is the best way add documentation. Also, I just saw that there's already seem to be some plan for adding additionnal "Inference" tools later, so it's all great
*In the "configuration\org.eclipse.osgi\bundles\177\1\.cp\resource\lua-5.1" folder
|
|
|
Re: Autocompletion for external API [message #1203336 is a reply to message #1173686] |
Fri, 22 November 2013 15:56 |
|
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 17:35] Report message to a moderator
|
|
| |
Re: Autocompletion for external API [message #1214437 is a reply to message #1211284] |
Wed, 27 November 2013 17:55 |
|
Thanks! This enhancement would be a nice little addition
Other than that, this is a bit off-topic, but I was wondering why does Koneki use luasocket for debugging, rather than let's say ZMQ? I known that luasocket isn't a developped a lot recently and you have to do some workaround in order to get lua 5.1 and 5.2 working. But I figured that there might be some good reasons like the fact that Lua XML-RPC use luasocket? So if the other lua tool for socket stay with luasocket it's better to stick with it?
Anyway, I was just wondering! Maybe I should just check more the source of Koneki to find out why.
[Updated on: Wed, 27 November 2013 18:01] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 02:05:26 GMT 2024
Powered by FUDForum. Page generated in 0.03813 seconds
|