aboutsummaryrefslogtreecommitdiff
path: root/nomsu.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-10-19 18:16:15 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-10-19 18:16:15 -0700
commitca5896b7bd8579e42a7fc9601e00512518051432 (patch)
treeaf356f2a5f2ed22b580f4b19f5fce5ee15a66ef2 /nomsu.moon
parentc7994cf72043936db1a5023c8475b0b64e0aaa21 (diff)
Finally fixed the bullshit way that string literals were converted to lua.
Diffstat (limited to 'nomsu.moon')
-rwxr-xr-xnomsu.moon22
1 files changed, 16 insertions, 6 deletions
diff --git a/nomsu.moon b/nomsu.moon
index 0642392..45099d0 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -600,18 +600,28 @@ end)]])\format(concat(lua_bits, "\n"))
initialize_core: =>
-- Sets up some core functionality
+ nomsu_string_as_lua = (code)=>
+ concat_parts = {}
+ for bit in *code.value
+ if type(bit) == "string"
+ insert concat_parts, bit
+ else
+ expr, statement = @tree_to_lua bit
+ if statement
+ @error "Cannot use [[#{bit.src}]] as a string interpolation value, since it's not an expression."
+ insert concat_parts, expr
+ return concat(concat_parts)
+
-- Uses named local functions to help out callstack readability
lua_code = (vars)=>
- inner_vars = setmetatable({}, {__index:(_,key)-> "vars[#{repr(key)}]"})
- lua = @tree_to_value(vars.code, inner_vars)
+ lua = nomsu_string_as_lua(@, vars.code)
return nil, lua
- @defmacro "lua > %code", lua_code
+ @defmacro "lua> %code", lua_code
lua_value = (vars)=>
- inner_vars = setmetatable({}, {__index:(_,key)-> "vars[#{repr(key)}]"})
- lua = @tree_to_value(vars.code, inner_vars)
+ lua = nomsu_string_as_lua(@, vars.code)
return lua, nil
- @defmacro "= lua %code", lua_value
+ @defmacro "=lua %code", lua_value
run_file = (vars)=>
if vars.filename\match(".*%.lua")