[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua plans to add meta-programming support?
- From: Xavier Wang <weasley.wx@...>
- Date: Sat, 10 Mar 2012 14:08:35 +0800
hi list,
Now we are discussing some semantics proposals in Lua. I believe that
the main solution is makes Lua easy to meta-programming. i.e., add
some hooks to llex, makes Lua can callbacks on lexing).
I love metalua, but it's too big, and parse lua all in memory. so if
Lua can provider a, e.g. token-filter, we can use it to generate
metalua ast, and pass it to sofunctions in the layer of
meta-programming,
A patch to lua is fairly easy, but beside the patch we also need a
module to generate ast, and it's maybe not so small. some idea is
here:
1. patching lua, and add a small ast module to lua std modules.
makes lua has native ability to handle meta-programming.
2. patching lua to add a lexer hook, and provider a c module using
this hook, but not add it to lua core.
3. extract llex.c from lua, and write a c module to produce ast,
makes a meta-programming module, and produce code string to lua.
1 will makes lua has native meta-layer. but it needs careful
implement, and need roberto agrees. and (the most important) need some
general mechanism, not some special ones, another issues is about how
to express it in lua code layer. maybe a "macro" keyword can be:
macro twoto(x)
local a = sym()
return tokens("local "..a.." = "..x.." return "..a.."*"..a)
end
of course it's a bad idea, but maybe we can workout a good notation.
but it will makes lua bigger and complex, which is not I want.
2. is better, do not affects current lua layer semantics, all things
can be done in C layer, but how to implement a module is somewhat need
discussing, it will affects the design of lexer hook.
3. can be do immediately, but it may makes lua code compiles twice.
Any discuss on this topic?