lua-users home
lua-l archive

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



On Aug 4, 2014, at 2:24 PM, Hao Wu <wuhao.wise@gmail.com> wrote:

On Mon, Aug 4, 2014 at 12:04 PM, Tim Hill <drtimhill@gmail.com> wrote:


What problem are you trying to solve? Annotations are typically used in compiled languages to carry over symbolic information to the run-time that would otherwise be discarded by the compiler. There are other ways to do this in Lua.

Ultimately, it would be just '--@annotation' becomes '@annotaion', for
less keystrokes.

What are other ways you are saying here by the way?


Well it depends on the problem domain. Essentially annotations are a way of embedding metadata in a source file that is then made available to the application at run-time via some introspective API (reflection etc). This is needed because in traditional compiled languages is it difficult to tunnel this information through the compiler.

But in languages like Lua the distinction between compile and run-time is much more blurred. Annotating (say) a table could be as simple as adopting a naming convention for table fields, or using a sub-table containing annotations. For example:

some_table = {
—@annotation(‘foo=10’, ‘bar=20’)
x = 10,
y = 20
}

Could just be:

some_table = {
_annotation = { foo=10, bar=20 },
x = 10,
y = 20
}

This requires nothing new in the language, just a conventional use of Lua tables. This can also work for user values (which can have an attached table), and closures (if the debug library is used, though I don’t endorse this approach).

—Tim