Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
LDT/Developer Area/Lua API Model 2
Lua API Model
The idea is to define a model of the external API of a lua file, a way to express a contract.
This model will be used as input of:
- a documentation generator,
- auto-completion engine,
- type checking at ide side.
File
A lua file declare some global variable and types. A file return values (this is the value you get when you require this file)
file .string shortdescription .string description .list(typedef) types .list(index) globalvars .list(returnvalues) returns
TypeDef
there are 2 (or 3) kind of typedef (oO)
typeDef=recordDef | funtionDef | scalarDef
a recorddef could by used to define a type of record(a tuple), a module or an object. (there still have some question "method")
recordDef .(string name) (anoymous recordDef could have no name) .string shortdescription .string description .list(index) fields
a functiondef allow to define a type of function. Most of the time, this function definition will be anonymous. But some times it could be usefull to name a kind of function (iterator function perhaps)
funtionDef .(string name) (anoymous functionDef could have no name) .string shortdescription .string description .list(parameter) params .list(returnvalues) returns
There are probably some scalar type which could not be instanciate by user (string,number,boolean,nil,self,any)
ScalarDef .string name
Parameter
parameter
.string name .typeref type .string description (.boolean optional) (.boolean hidden)
Remarks: Hidden could be usefull, if we have a parameter we don't want to expose in the API Remarks: Perhaps hidden and optional does not need to be in the 1st version.
Index
Questions?: Not sure Index was a good name Questions?: Must we make a difference between Parameter and index an index is a named reference to a type
index .string name .string shortdescription .string description .typeref type
TypeRef
It's a reference to a type. There 3 kind of reference.
typeref: externaltyperef | internaltyperef |inlinetyperef externaltyperef .string modulename .string typename internaltyperef .string typename inlinetyperef .typedef
Return values
a values return has references to a type define in the lua file. a values return is a list of possible value to return.
e.g. if a function return a number or nil and err. you function will have 2 return values :
- number a result - nil, err if an error occured
return .list(typeref) types .string description (.defaultuse)
Remarks: Perhaps we could have a defaultuse entry to define the return value the type checking should use.