diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2017-09-07 09:38:54 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2017-09-07 09:38:54 -0700 |
| commit | d218dcbd4217a8881f9a3e500ba17cd24e6e77f8 (patch) | |
| tree | e12c4cc6440b635e52d583ad8fd167ac3f866b6c /core.moon | |
| parent | e8f2b4fdd263e90e40ff4e6b950296045ac8a7ea (diff) | |
Added comments.
Diffstat (limited to 'core.moon')
| -rwxr-xr-x | core.moon | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -39,17 +39,24 @@ g = PermissionNomic() g\defmacro [[lua %lua_code]], (vars,helpers,ftype)=> with helpers lua_code = vars.lua_code.value - escapes = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r" - unescape = (s)-> s\gsub("\\(.)", ((c)-> escapes[c] or c)) + as_lua_code = (str)-> + switch str.type + when "String" + escapes = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r" + unescaped = str.value\gsub("\\(.)", ((c)-> escapes[c] or c)) + return unescaped + + when "Longstring" + result = [line for line in str.value\gmatch("[ \t]*|([^\n]*)")] + return table.concat(result, "\n") + else + return str.value + switch lua_code.type when "List" -- TODO: handle subexpressions - .lua table.concat[unescape(i.value.value) for i in *lua_code.value] - when "String" - .lua(unescape(lua_code.value)) - when "Longstring" - .lua(lua_code.value) - else error("Unknown type: #{lua_code.type}") + .lua table.concat[as_lua_code(i.value) for i in *lua_code.value] + else .lua(as_lua_code(lua_code)) return nil g\def {"restrict %fn to %whitelist"}, (vars)=> @@ -106,6 +113,9 @@ g\def [[printf %str]], (args)=> for s in *args.str do io.write(utils.repr(s)) io.write("\n") +g\def [[concat %strs]], (vars)=> + return table.concat([utils.repr(s) for s in *vars.strs], "") + g\def [[quote %str]], (vars)=> return utils.repr(vars.str, true) |
