Skip to content

Instantly share code, notes, and snippets.

@leetking
Created February 12, 2019 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leetking/5a09955aacc8284a89e881dc19eb0b3e to your computer and use it in GitHub Desktop.
Save leetking/5a09955aacc8284a89e881dc19eb0b3e to your computer and use it in GitHub Desktop.
try implement the macro in Lua
-- try to implement a naive macro in Lua
-- TODO complete it
function syntax(name)
assert(type(name) == "string")
local name, args = name:match("([%w_]+)%(?([%w_,]+)%)?")
return function(body)
assert(type(body) == "string")
end
end
function fun(body)
load("function "..body)()
end
-- define a macro
syntax "fun(body)"
[[
function body
]]
lamba = function()
var = 10
-- use a macro
fun [[foo()
print(var)
end]]
foo()
end
lamba()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment