Skip to content

Instantly share code, notes, and snippets.

@bakpakin
Created January 26, 2019 00:44
Show Gist options
  • Save bakpakin/961e7d4c9356dca1dbc73ded8889af31 to your computer and use it in GitHub Desktop.
Save bakpakin/961e7d4c9356dca1dbc73ded8889af31 to your computer and use it in GitHub Desktop.
New code injection special
-- (lua "print('hello!')") -> prints hello, evaluates to nil
-- (lua "print 'hello!'" "10") -> prints hello, evaluates to the number 10
-- (lua nil "{1,2,3}") -> Evaluates to a table literal
SPECIALS['lua'] = function(ast, scope, parent)
assertCompile(#ast == 2 or #ast == 3,
"expected 2 or 3 arguments in 'lua' special form", ast)
if ast[2] ~= nil then
table.insert(parent, {leaf = tostring(ast[2]), ast = ast})
end
if #ast == 3 then
return tostring(ast[3])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment