lua-users home
lua-l archive

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


This looks great. I especially like how you used BeginEndProposal as
one of the examples. Of course, the problem for coders like me who are
using Lua standalone and not embedding is getting Debian, Ubuntu,
Fedora, etc. to package a tokenf Lua - not because I'm not comfortable
compiling from source, but because my users might not be.

One question, though - what about load, loadfile, and loadstring? Will
macros defined in the caller automatically be applied in the sources
they load?

-- LeafStorm
"There are 10 types of people in the world - those who understand
binary and those who don't."



On Tue, Jan 19, 2010 at 3:53 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> 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.
>