lua-users home
lua-l archive

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


On Tue, Mar 29, 2011 at 1:07 PM, Francesco Abbate
<francesco.bbt@gmail.com> wrote:
> example:
> -- we declare two local variables each one with two components
> local a[2], b[2]
>
> -- be is initialized with two values
> b = 2, 3
>
> -- the following means two assignements!
> a = b

Funny enough, I've been doing experiments with the next generation of
LuaMacro (which generates Lua source rather than depending on the
token filter patch, but that's another story)

This introduces the idea of lexically-scoped macros, and one of the
examples I have does this:

tuple[3] A,B  -> expands to local A_1,A_2,A_3,B_1,B_2,B_3

A = 10,20,30  --> expands to A_1,A_2,A_3 = 10,20,30

and so forth - 'A = B' works naturally as well.

Macro expansion can depend on the context, so that

do_(i,1,3,
  A = B + 1
)

expands to

A_1 = B_1 + 1
A_2 = B_2 + 1
A_3 = B_3 + 1

That is, it is exactly the kind of short loop unrolling needed for
efficient LuaJIT code. Since it's a preprocessor no core modifications
needed. I should be able to make an announcement once the new Penlight
has been released.

steve d.