lua-users home
lua-l archive

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




On Sun, Nov 4, 2018, 1:28 PM Dirk Laurie <dirk.laurie@gmail.com wrote:
> {                                           -- starts a new local context (closure)
>  [:      ref0 = 'k1'] = :      ref1 = v1,   -- ['k1'] = v1   and set external ref0 = 'k1'
>  [:      ref2]        =               v2,   -- [1]    = v2   and set local    ref2 = 1
>  [:local ref3]        =               v3,   -- [2]    = v3   and set local    ref3 = 2
>  [:local ref4 = 'k2'] = :local ref5 = v4,   -- ['k2'] = v4   and set local    ref4 = 'k2', local    ref5 = v4
>  [:local ref6 = 'k3'] = :      ref7 = v5,   -- ['k3'] = v5   and set local    ref6 = 'k2', external ref7 = v5
>                  k4   =               ref0, -- ['k4'] = 'k1'
>  [              'k5'] =               ref2, -- ['k5'] = v2
>                                       ref1, -- [3]    = v1
> }                                           -- close the local context

Why is this better than writing it out in plain Lua that everyome can
already understand?

I understand the intent is that it can express internal references (possibly circular) in a single literal instead of having to write the plain object and then imperatively link in the references using subsequent statements.

This could be implemented by a preprocessor that translates it into an IIFE that does exactly that.

/s/ Adam