lua-users home
lua-l archive

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


This package, which is loosely based on steve d.'s LuaMacro code[1,2], implements textual macros for Lua. WRT to steve's module I changed the lexer and the way macros are defined and expanded and also streamlined most functions. Macros can now be defined in the same file in which they're used; macros in macros are possible as well. The expansion part of a macro is now normal Lua code (i.e. it's neither a string nor are there special delimiters necessary). The module requires a version of Lua with lhf's token filter code patched in. To use it, call Lua with a script filename like that: lua -l macro test.lua or lua -l macrolpeg test.lua As you can see, there are two similar implementations; both are pure Lua. macro.lua uses a lexer that's based on Lua's pattern matching while macrolpeg.lua works with an lpeg-based lexer. I have tweaked and tested both lexers with many small and big files; both seem to work reasonably well. However, there may still be cases where either (or both) produce nonsense: I'd very much like to hear about such problems. For larger files the lpeg-based lexer is significantly faster than the pattern-matching lexer but to see any measurable difference you'd have to feed them several dozen KB worth of stuff. For the macro package the differences are probably negligible. Development was originally done for the next beta version of Idle; I "backported" the code to Lua 5.1.3. All tests were done under Windows but I think the whole thing should work with any Lua 5.1.x version so long as the token filter patch is available. If there's something not working as it should please drop me a note (however, see the readme if you run into trouble with a lua interpreter, like lua.exe, in interactive mode). Time permitting I will scrape together some documentation; till then the example scripts and the source code should show the way forward:-) Download full source and examples: http://thomaslauer.com/download/LuMaX.zip [1] http://luaforge.net/projects/luamacro/ [2] http://lua-users.org/wiki/LuaMacros