aboutsummaryrefslogtreecommitdiff
path: root/nomic.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-08-18 21:08:28 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-08-18 21:08:28 -0700
commitdc152f88b6ff1d778a8106ee49b8c4e3d902404a (patch)
treedfd2471cab5de49b8b1472f00236b566e169f8b4 /nomic.moon
parentb2d49dde55522429f805590c40f96a95bfc67106 (diff)
Cleanup and utils file.
Diffstat (limited to 'nomic.moon')
-rw-r--r--nomic.moon19
1 files changed, 10 insertions, 9 deletions
diff --git a/nomic.moon b/nomic.moon
index 2a03080..0eb9879 100644
--- a/nomic.moon
+++ b/nomic.moon
@@ -4,10 +4,10 @@ moon = require 'moon'
type = moon.type
is_list = (t)->
- i = 0
+ i = 1
for _ in pairs(t)
- i += 1
if t[i] == nil then return false
+ i += 1
return true
repr = (x)->
@@ -105,17 +105,18 @@ FunctionCall = (tokens)->
code = table.concat(ret, "\n")
return code
-Thunk = (lines)->
+Thunk = (statements)->
ret = {}
add_line ret, "function(game, locals)"
indent!
- for i,line in ipairs lines
- if line\match "locals%[\".*\"%] = .*"
- table.insert ret, indent_block(line)
- elseif i == #lines
- table.insert ret, indent_block("return "..line..";")
+ for i,statement in ipairs statements
+ -- TODO: clean up? This is a bit hacky. I should *know* if this is a var assignment.
+ if statement\match "locals%[\".*\"%] = .*"
+ table.insert ret, indent_block(statement)
+ elseif i == #statements
+ table.insert ret, indent_block("return "..statement..";")
else
- table.insert ret, indent_block(line..";")
+ table.insert ret, indent_block(statement..";")
dedent!
add_line ret, "end"
return table.concat(ret, "\n")