Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local macros = {
- ["@"] = {
- pat = "@(%b())";
- fn = function(_f)
- local f = _f:sub(2, -2)
- :gsub("@0", "a")
- :gsub("@(%d)", "a[%1]")
- :gsub("@", "return ")
- return "(function(...) local a = {...} "..f.." end)"
- end;
- };
- ["$"] = {
- add = [[
- local get_file_macro = setmetatable({}, {
- __index = function(self, _k)
- if not fs.exists(_k) then
- fs.open(_k, "w").close()
- end
- local h = fs.open(_k, "r")
- local text = h.readAll()
- h.close()
- return text
- end;
- __newindex = function(self, _k, _v)
- if type(_v) == "string" then
- local h = fs.open(_k, "w")
- h.write(_v)
- h.close()
- end
- end;
- })
- ]];
- pat = "$(%b())";
- fn = function(_f)
- local f = _f:sub(2, -2)
- return "get_file_macro["..f.."]"
- end;
- };
- }
- return function(_str, ...)
- local str, arg = _str, {...}
- for macro in _str:gmatch("#macro%s+(%S+)") do
- local use_macro = macros[macro]
- str = (use_macro.add or "")..str
- if use_macro.pat and use_macro.fn then
- str = str:gsub(use_macro.pat, use_macro.fn)
- end
- end
- return str
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement