how to annotate lua source-code to specify behaviour ?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

how to annotate lua source-code to specify behaviour ?

Valerio
Hi,
is there some easy way to annotate Lua source, similarly to what happens with the @Annotate mechanism in Java? 
Ideally, such annotations should assigned to variables, tables and functions. 
Annotations should be assigned to behaviours triggered by operations that are specific to each type of annotation. 

Something like this:
 --begin lua code
[[@some_annotation]]
table={}

The effect of the presence of the annotation should be reflected by the init of the table's meta-table to trigger some application-specific action.

Without such annotation mechanism, I can only see the following alternatives, which would however require
some more efforts:
- somehow override the table creation mechanism so that the table's metatables are automatically modified upon creation
- similarly for variables and functions


Any suggestion is greatly appreciated. 


valerio
Reply | Threaded
Open this post in threaded view
|

Re: how to annotate lua source-code to specify behaviour ?

Nagaev Boris
On Thu, Mar 26, 2015 at 11:22 PM, Valerio Schiavoni
<[hidden email]> wrote:

> Hi,
> is there some easy way to annotate Lua source, similarly to what happens
> with the @Annotate mechanism in Java?
> Ideally, such annotations should assigned to variables, tables and
> functions.
> Annotations should be assigned to behaviours triggered by operations that
> are specific to each type of annotation.
>
> Something like this:
>  --begin lua code
> [[@some_annotation]]
> table={}
>
> The effect of the presence of the annotation should be reflected by the init
> of the table's meta-table to trigger some application-specific action.
>
> Without such annotation mechanism, I can only see the following
> alternatives, which would however require
> some more efforts:
> - somehow override the table creation mechanism so that the table's
> metatables are automatically modified upon creation
> - similarly for variables and functions
>
>
> Any suggestion is greatly appreciated.
>
>
> valerio

Hello,

LDoc - A Lua Documentation Tool [1] provides annotations for functions
like this:

--- Summary ends with a period.
-- Some description, can be over several lines.
-- @param p1 first parameter
-- @param p2 second parameter
-- @return a string value
-- @see second_fun
function mod1.first_fun(p1,p2)
end

[1] https://github.com/stevedonovan/ldoc

Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: how to annotate lua source-code to specify behaviour ?

Valerio
Hi,
I assume LDoc, as the name says, seems to be a documentation tool, which are then fed to some parsing tool to produce documentation. 
I'm not sure how this is relevant for my use-case, where the annotation should somehow guide/modify the runtime behaviour of the annotated entity (be it a table, a function, a variable, etc). 

best,
valerio

On Fri, Mar 27, 2015 at 12:31 AM, Nagaev Boris <[hidden email]> wrote:
On Thu, Mar 26, 2015 at 11:22 PM, Valerio Schiavoni
<[hidden email]> wrote:
> Hi,
> is there some easy way to annotate Lua source, similarly to what happens
> with the @Annotate mechanism in Java?
> Ideally, such annotations should assigned to variables, tables and
> functions.
> Annotations should be assigned to behaviours triggered by operations that
> are specific to each type of annotation.
>
> Something like this:
>  --begin lua code
> [[@some_annotation]]
> table={}
>
> The effect of the presence of the annotation should be reflected by the init
> of the table's meta-table to trigger some application-specific action.
>
> Without such annotation mechanism, I can only see the following
> alternatives, which would however require
> some more efforts:
> - somehow override the table creation mechanism so that the table's
> metatables are automatically modified upon creation
> - similarly for variables and functions
>
>
> Any suggestion is greatly appreciated.
>
>
> valerio

Hello,

LDoc - A Lua Documentation Tool [1] provides annotations for functions
like this:

--- Summary ends with a period.
-- Some description, can be over several lines.
-- @param p1 first parameter
-- @param p2 second parameter
-- @return a string value
-- @see second_fun
function mod1.first_fun(p1,p2)
end

[1] https://github.com/stevedonovan/ldoc

Best regards,
Boris Nagaev


Reply | Threaded
Open this post in threaded view
|

Re: how to annotate lua source-code to specify behaviour ?

Nagaev Boris
On Thu, Mar 26, 2015 at 11:42 PM, Valerio Schiavoni
<[hidden email]> wrote:
> Hi,
> I assume LDoc, as the name says, seems to be a documentation tool, which are
> then fed to some parsing tool to produce documentation.
> I'm not sure how this is relevant for my use-case, where the annotation
> should somehow guide/modify the runtime behaviour of the annotated entity
> (be it a table, a function, a variable, etc).
>
> best,
> valerio

Sorry, I misunderstood your original question. I saw LDoc-like syntax
and made the connection.

Now I see that this thing is more close to Python's decorators. Am I correct?

Can you provide complete use case, please?

Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: how to annotate lua source-code to specify behaviour ?

Daurnimator
In reply to this post by Valerio
On 27 March 2015 at 10:42, Valerio Schiavoni
<[hidden email]> wrote:
> I'm not sure how this is relevant for my use-case, where the annotation
> should somehow guide/modify the runtime behaviour of the annotated entity
> (be it a table, a function, a variable, etc).
>
> best,
> valerio

Just pass your object through a function: the wonders of first class
functions! :)
For tables and strings the lack of required () make it quite pleasant to the eye

Reply | Threaded
Open this post in threaded view
|

Re: how to annotate lua source-code to specify behaviour ?

Michal Kolodziejczyk-3
In reply to this post by Valerio


On 27.03.2015 00:22, Valerio Schiavoni wrote:
> Hi,
> is there some easy way to annotate Lua source, similarly to what happens
> with the @Annotate mechanism in Java?
> Ideally, such annotations should assigned to variables, tables and
> functions.
> Annotations should be assigned to behaviours triggered by operations
> that are specific to each type of annotation.

There is nothing built-in, but see wiki for ideas:
http://lua-users.org/wiki/DecoratorsAndDocstrings

Regards,
miko