lua-users home
lua-l archive

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


If that's really what you want, the piece of metalua code below will do it (put it in your code between "-{block: ...}" in the file you want to hack, or put it in lib/extension/ and call the extension from the file with a "-{ extension '...'}").

However, In practice, I don't think you need this. I use table.transpose(), in metalua base lib, to exchange keys and values, so table.transpose{ "foo", "bar" } will eval to { foo=1, bar=2 }. Such statements typically aren't in performance bottlenecks, so there's nothing meaningful to gain by precompiling them off-line.

In case you want to understand the code below:

-{extension 'xmatch'}

mlp.table_field = gg.multisequence{
   default = mlp.table_field,
   { '[', mlp.expr, ']', gg.onkeyword { '=', mlp.expr }, builder =
     match function
     | { e, false } -> return `Pair{ e, `True }
     | { k, v }     -> return `Pair{ k, v }
     end } }

-- Fabien.