Help understanding code assist [message #1012000] |
Wed, 20 February 2013 17:00 |
Eclipse Guest Messages: 93 Registered: February 2013 Location: Vienna |
Member |
|
|
I'm relatively new to Lua, and very new to Koneki. I've setup the LDT tool and been able to get a project setup and working with most functionality. I'm confused though on exactly what I can auto-complete and ctrl-click. If everything is local it seems that things are working okay, but I'm trying to figure out what I can do with modules.
To be specific -
If I have
-- simpleModuleA.lua
module(..., package.seeall)
function myFunc()
print('hello')
end
-- useModule.lua
local myModA = require('simpleModuleA')
-- insert question code here.
If at the point noted in the code I start typing "myMo" and then hit ctrl-space it will auto complete the local variable "myModA". However, if then have "myModA." and hit ctrl-space I do not get any suggestions for available functions. Is this normal?
Also if I have in the code "myModA.myFunc()" I cannot ctrl-click on "myFunc" and go to the definition of myFunc. However, if I ctrl-click on "MyModA" and get taken to the declaration of myModA.
Is this the expected behavior or do I have something set up wrong. I would really like the ability to ctrl-click into my modules or have auto-complete for functions.
Also, when I am writing simpleModuleA I have to have everything 'global' in that file (i.e. "function myFunc" instead of "local function myFunc") in order to have it visible when I try to do myModA.myFunc. If that is the case I can't have any auto completion on that function when writing that file because it is a global?
Thanks for helping me understand this.
|
|
|
Re: Help understanding code assist [message #1012414 is a reply to message #1012000] |
Thu, 21 February 2013 14:24 |
Kevin KIN-FOO Messages: 58 Registered: January 2010 |
Member |
|
|
Hi Kevin,
About modules, the module function won't work with Lua 5.2. So, you might start to create modules from tables. Then, in this case, you will not handle any globals.
local M = {}
M.myFunc = function()
print('hello')
end
return M
As I'm writing, we analyze modules from their documentation comments[1]. Your module was not documented, that is why you did not have content assist available on it. Once documented, Ctrl-clicking your module's attributes will lead you to their documentation.
To unleash Koneki LDT you might read its Getting Started[2] from its User Guide[3], thanks for your feedback.
Kévin
[1] Lua Documentation Language: http://wiki.eclipse.org/Koneki/LDT/User_Area/Documentation_Language
[2] Getting Started: http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_0.9#Getting_started
[3] User Guide: http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_0.9
|
|
|
|
|
|
|
Re: Help understanding code assist [message #1014773 is a reply to message #1013149] |
Tue, 26 February 2013 12:48 |
Marc Aubry Messages: 86 Registered: August 2012 |
Member |
|
|
Hi Kevin,
You're right, the @type is the clue.
The @type allow to define a kind of set/container of functions and fields. You can also associate a type to a variable such as a function return or a field.
If a variable have a defined type, the auto-completion will known all the functions and fields available on it.
To fix your code, you just need to declare the new type "mytable" using @type,
set the field type to #mytable instead of #table, and set the parent of MyFunc to "#mytable".
---
-- Simple Module for testing documentation.
-- Just for test.
--
-- @module docTest
local M = {}
--- @type mytable
---
-- A Table.
-- What should this be??? A field, a Type?
--
-- @field [parent=#docTest] #mytable myTable
M.myTable = {}
---
-- Function in a table.
-- What should the parent be???
--
-- @function [parent=#mytable] myFunc
function M.myTable.myFunc()
-- Do something
end
return M
Now, when you require the module "testdoc" in an other file. The test variable will be associated to the type "docTest", so you can call the field "mytable". And as the field myTable is associated with the type "mytable" the function "myfunc" is available for the auto completion.
I hope theses explanations can help you.
Feel free to post here if you have any feedback on this mechanic or the documentation, it's helpful for us to understand Lua developer point of view.
Marc
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04863 seconds