lua-users home
lua-l archive

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




On Fri, Nov 4, 2011 at 10:24 AM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> you can product bytecode file with metalua, without parse it runtime.

Good but I really meant generating source code becaus then it can be shared
and reused and also modified if needed.

require 'metalua.ast_to_string'

ast_to_string(ast) will translate an AST into a source string, although formatting (comments and line numbers) will obviously be lost. 

Caveat: for the resulting source to be Lua 5.1 compatible, it must not use nodes `Goto{ }, `Label{ } nor `Stat{ }. The two former are trivial to adapt to Lua 5.2, though, and `Stat{ } can be translated in a slow but functionally equivalent anonymous function call (care must be taken of returns and varargs in the body). Anyway, you don't need any of these for simple cases such as the one discussed here.