lua-users home
lua-l archive

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


Not that hard. There are 3 extensions in Metalua wrt Lua 5.1: `Label{ }, `Goto{ } and `Stat{ }. The two formers are in Lua 5.2 and LuaJIT2, so we're only left with the latter, which allows to put a statement where an _expression_ was expected.

`Stat{ block, expr } is an _expression_ which executes block and evaluates to expr in block's scope (same principle as with repeat block until expr). It's intended for macros, not for regular code. It can be encoded as: +{ (function() -{block}; return -{expr} end)() }. This is incorrect in Lua 5.1 because of interferences between functions and getfenv/setfenv, but I've understood that these have been dropped from Lua 5.2 and LuaJIT2. And I seem to remember that LuaJIT was pretty good at inlining functions, so there won't even be a performance penalty.

One last trick would be to make gensym() generate legal variable names, but that's trivial as long as we agree on a reserved prefix.

However, line numbers in stack traces would remain completely messed up, which makes the debugging process tedious and beginner-hostile. CoffeeScript and some other compilers targeting _javascript_ maintain some source->destination line number conversion tables; This might be worth investigting. Do you know how MoonScript addresses it?