Created
February 12, 2019 09:40
-
-
Save leetking/5a09955aacc8284a89e881dc19eb0b3e to your computer and use it in GitHub Desktop.
try implement the macro in Lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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