[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] LuaMacro 1.5
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 19 Jan 2010 10:53:17 +0200
Hi all,
The writeup (and links) are here:
http://lua-users.org/wiki/LuaMacros
The four big changes in this release are:
(1) Can use a simplified string macro definition style (suggested by
Thomas Lauer and coming from his work on Idle) which can be used in
the same source file as its uses:
__def 'dump(x) print(_STR(x).." = "..tostring(x))'
hello = 42
dump(hello)
=>
hello = 42
(2) Macro names can be general tokens, e.g. here is a implementation
of lhf's short lambda syntax:
(http://lua-users.org/lists/lua-l/2009-12/msg00140.html)
macro.define ('\\', {'args','body';handle_parms = true},
'function(args) return body end',
function(ls) -- grab the lambda
-- these guys return _arrays_ of token-lists. We use '' as the delim
-- so commas don't split the results
local args = macro.grab_parameters('(','')[1]
local body = macro.grab_parameters(')','')[1]
return args,body
end
)
So \x(x+1), \x,y(x+y), \x\y(x+y) etc work as expected.
(3) Macros can install lexical scanners that look for end-of-block.
So handler(function(...) ... end) can be written like handler begin ... end
(which is LeafStorm's BeginEndProposal (see wiki page))
macro.define ('begin',nil,function()
macro.set_end_scanner 'end)'
return '(function(...)'
end)
(4) the __line builtin macro can be used to set the line number
information that the parser sees:
__line 30
(this code starts on line 30)
...
__line 100
(etc)
Unfortunately, not possible to set the _filename_ that the parser
sees; this would require a patch to the token filter patch.
Not for everybody, but can be very useful in custom debugging and
testing code. And can make writing DSLs easier.
For the curious who are living on Windows without a compiler, here is
a token-patched version of Lua 5.1.4 (only 72K !!)
http://luaforge.net/frs/download.php/4330/lua514-tokenf-win32.zip
(not LfW compatible, compiled with mingw)
Remember as always, that a token-patched Lua compiler can write
compatible bytecode.
steve d.