|
On Aug 4, 2014, at 2:24 PM, Hao Wu <wuhao.wise@gmail.com> wrote:
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 |