Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [koneki-dev] The Record-block/Type-block

Hi Simon,
OK I think I understand it better now.  Thanks!

When I said "enums" what I meant was that some APIs expose C/C++ enums as named Lua variables of number values, in the global table or sub-tables.  If they only put one enum list/type in the sub-table, then it would just be @type+@fields, where the @type is the sub-table name and @fields are the enum/variables, right?  But due to poor design, or lack of forethought, or whatever, some APIs have many different enum lists/types they put in the same sub-table or in the global.  So instead of namespacing by using separate Lua sub-tables, they're all jumbled together in one table.

So for example, suppose you had PCRE compilation/execution flag enums used during compilation/execution of a regex, and a set of PCRE error flag enums used for return values, and you put both sets of flags (which are just variable=value) in the same Lua sub-table. From a Lua perspective they're just table fields.  But from a documentation/help and ctrl-space completion perspective, you'd want LDT to show them as separate "types" or namespaces.

Makes sense?

So I thought this one you suggested would do it (putting this in globals.lua): 
------------------------------------------------------------------------------
-- description.
-- @field[parent =#global] regex#PcreFlags PcreFlags

But that still treats it as a sub-table of the global table.

But now I'm thinking this other one you suggested is the correct one to do:
------------------------------------------------------------------------------
-- description.
-- @field[parent =#global] #PcreFlags PcreFlags

Yes as you noted it's bad style to pollute a table that way.  We do it right now in our API but I'm lobbying we change, and I think Wireshark's Lua-API might do it but I'm not positive. (I haven't used their Lua stuff in a while, but I hope to get to documenting their's in LDT someday as well :)

-hadriel


From: Simon Bernard <sbernard@xxxxxxxxxxxxxxxxxx>
To: Hadriel Kaplan <hadrielk@xxxxxxxxx>; General development dicussions for the Koneki project <koneki-dev@xxxxxxxxxxx>
Sent: Wednesday, February 29, 2012 6:38 AM
Subject: RE: [koneki-dev] The Record-block/Type-block

Hi,
Thanks for your feedback !
 
1) For the ‘#’
We decided to have a way to visualize easily and quickly the difference between a type name and something else (and technically it also helps for the parsing). For the type name (when we use the @type tag), we had the choice between being compliant with the type notation we chose (thus, use a '#') or being compliant with the other tags (where the first word which doesn’t start by a '#' is the name of the element)
We chose the first solution (but this could change).
 
2) For the @field tag
The @field tag in a @type block is the same thing than creating a @field block and attaching it to a type thanks to the parent modifier.
 
The two different notations are equivalent:
------------------------------------------------------------------------------
-- short description.
-- long description
-- @type #recordtypename
-- @field #typeref fieldname description
local t = {fieldname = 'foo'}
 
Or :
------------------------------------------------------------------------------
-- short description.
-- long description
-- @type #recordtypename
local t = {}
 
------------------------------------------------------------------------------
-- description.
-- @field[parent =#recordtypename] #typeref fieldname
t.fieldname = 'foo'
 
For the content assist (ctrl-space) problem, I retested it and it seems to work. In your PCRE flags snippet, you made a mistake: @type PcreFlags should be @type #PcreFlags ; as I said in 1) perhaps we should change this.
 
3) For the enum
We don’t really have support for enums (as we want to be as close as possible from Lua)
It is still possible to express enums like this :
------------------------------------------------------------------------------
-- The PCRE flags
-- @type #PcreFlags
-- @field #number PCRE_EXTENDED
-- @field #number PCRE_MULTILINE
-- @field #number PCRE_CASELESS
 
------------------------------------------------------------------------------
-- A function to compile a PCRE regex pattern
-- @function [parent=#regex] new
-- @param #string pattern
-- @param #number flags
-- @return #userdata The compiled regex object
-- @return #nil, #string Returns nil and error string on failure
 
Or like this :
------------------------------------------------------------------------------
-- The PCRE flags
-- @type #PcreFlags
-- @field #PcreFlag PCRE_EXTENDED
-- @field #PcreFlag PCRE_MULTILINE
-- @field #PcreFlag PCRE_CASELESS
 
------------------------------------------------------------------------------
-- A function to compile a PCRE regex pattern
-- @function [parent=#regex] new
-- @param #string pattern
-- @param #PcreFlag flags  
-- @return #userdata The compiled regex object
-- @return #nil, #string Returns nil and error string on failure
 
At the moment, the parameter type is not used by the IDE so it is just here for documentation purposes.
 
Now that you created your PcreFlags type, you need to define how it could be accessed. There are 3 solutions:
 
* A global variable preloaded by your VM, so you need to add this to the global.lua file :
 
------------------------------------------------------------------------------
-- description.
-- @field[parent =#global] regex#PcreFlags PcreFlags
 
* A field in your module (in regex.lua)
 
------------------------------------------------------------------------------
-- description.
-- @field[parent =#regex] #PcreFlags PcreFlags
 
* Indicate that your module modifies the global environment when it is loaded, by adding this in your module (regex.lua)
 
------------------------------------------------------------------------------
-- description.
-- @field[parent =#global] #PcreFlags PcreFlags
 
This last solution is not supported by content assist (ctrl-space) for now, and we thought that a module should modify the global environment as less as possible.
 
4) return values
You can have as many @return tags as you want for a function.
The first one is used for type inference, and the others are just for documentation.
It seems you use it well, then.
 
Hope this helps! ;)
 



Back to the top