Skip to content

Instantly share code, notes, and snippets.

@bakpakin
bakpakin / fennel-lua.lua
Created January 26, 2019 00:44
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
SPECIALS['lua'] = function(ast, scope, parent)
table.insert(parent, {leaf = ast[2], ast = ast})
end

Keybase proof

I hereby claim:

  • I am bakpakin on github.
  • I am calsrose (https://keybase.io/calsrose) on keybase.
  • I have a public key ASD62xnhgH6qEJAsaF1kQTKnIh0fDV-TGC_zX43VZpx7QAo

To claim this, I am signing this object: