aboutsummaryrefslogtreecommitdiff
path: root/nomsu_compiler.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-08-29 14:19:16 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-08-29 14:20:18 -0700
commite64632be1aa938c865d06acfcf6641b75ecb42ac (patch)
tree9d9dfd28c032748fa4bb4ce2be600158fef3c2f7 /nomsu_compiler.moon
parent436982c6ba5cbdebfaa28b455b5d0695067de146 (diff)
Switched "as_lua_id" to not add an underscore by default, and just add
it manually to variables and A_ as a prefix to actions. Now, by default, classes and method calls don't use the A_ prefix, which means nomsu can more easily play nice with regular Lua objects.
Diffstat (limited to 'nomsu_compiler.moon')
-rw-r--r--nomsu_compiler.moon18
1 files changed, 10 insertions, 8 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 0c9b9af..e05c209 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -35,7 +35,7 @@ string.as_lua_id = (str)->
str = gsub str, "%W", (c)->
if c == ' ' then '_'
else format("x%02X", byte(c))
- return '_'..str
+ return str
table.map = (fn)=> [fn(v) for _,v in ipairs(@)]
table.fork = (t, values)-> setmetatable(values or {}, {__index:t})
@@ -338,8 +338,8 @@ with NomsuCompiler
.compile = (tree)=>
if tree.version
- if get_version = @['A'..string.as_lua_id("Nomsu version")]
- if upgrade = @['A'..string.as_lua_id("1 upgraded from 2 to 3")]
+ if get_version = @['A_'..string.as_lua_id("Nomsu version")]
+ if upgrade = @['A_'..string.as_lua_id("1 upgraded from 2 to 3")]
tree = upgrade(tree, tree.version, get_version!)
switch tree.type
when "Action"
@@ -354,7 +354,12 @@ with NomsuCompiler
"Compile-time action:\n%s\nfailed to produce any Lua"
return ret
- lua = LuaCode.Value(tree.source, "A",string.as_lua_id(stub),"(")
+ lua = LuaCode.Value(tree.source)
+ if tree.target
+ lua\append @compile(tree.target), ":"
+ else
+ lua\append "A_"
+ lua\append(string.as_lua_id(stub),"(")
args = {}
for i, tok in ipairs tree
if type(tok) == "string" then continue
@@ -372,9 +377,6 @@ with NomsuCompiler
insert args, arg_lua
lua\concat_append args, ", "
lua\append ")"
- if tree.target
- target_lua = @compile(tree.target)
- lua\prepend(target_lua, ":")
return lua
when "EscapedNomsu"
@@ -496,7 +498,7 @@ with NomsuCompiler
return LuaCode.Value(tree.source, tostring(tree[1]))
when "Var"
- return LuaCode.Value(tree.source, string.as_lua_id(tree[1]))
+ return LuaCode.Value(tree.source, "_", string.as_lua_id(tree[1]))
when "FileChunks"
error("Cannot convert FileChunks to a single block of lua, since each chunk's "..