lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I start a new post since this is also an introduction to my solution of the
annotation system.

I don't think it's good to handle the annotation in the C side, since  a
generic annotation system should provide supports for many scenarios. 

I used an attribute system to handle features like type validation for both
parameters and return values, iterator generator, data table and field
binding, web route, web form validation and etc, they can be easily done in
the Lua side, but can hardly be done in the C side.

As an example, if we can bind basic types for function parameter, and let
the C side to handle it, it's not enough to cover all conditions. The system
can't handle types like enumeration values, fixed-structure data values and
etc, or we need have a new ML to do the job, that's against the Lua's
design(also we can't repeat to declare the same type in each annotation, so
we also need to bring in a new type system).

The key of my solution is the Lua environment and global variable, through a
private and well-controlled environment, we know every definition of global
variables in it, we have the target name, type and where it's defined, so we
also can apply annotations to the target, like wrap the target function for
type validation, register an object as route handlers. We can create our own
type system and annotation system without any changes of the Lua.

Here is an example to show the usage of it:

I choose the __XXX__ format since it's easily to let the editor to highlight
it. They are objects that can be created with many declaration styles. When
I need change the JSON output to a html string, I only need replace the
__Json__ to __View__ "template_path" so I don't need to modify the main
logic in the function.

For other common usages:

The solution of mine is not a simple project, and it may be more heavy for
Lua to provide an annotation system in the C side, I really enjoy the Lua's
simple state for now, so I hope it'd keep it in the future, since we can
finish the job from the outside.

And If anyone has interesting in my project, you can find it at

Sent from: