lua-users home
lua-l archive

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


On Mon, Aug 4, 2014 at 6:32 PM, Tim Hill <drtimhill@gmail.com> wrote:
>
> 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).

This makes sense to me. My requirement was more like to annotate
functions or statements:

@param(string, integer)
@return(string)
function foo(bar0, bar1) end

or

@attribute(readonly)
local cube_size = 10

or

@condition(debug)
local function print() end

so it will still work ignoring the annotations while the
post-processor can take a further step to 'optimize' or 'understand'
the semantics. Its only purpose is to be 'compatible' with the
standard interpreter in a simpler format. This can of course be done
in various ways, what I was asking for is this input can be understood
by the standard interpreter.

>
> —Tim
>
>