From dc152f88b6ff1d778a8106ee49b8c4e3d902404a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 18 Aug 2017 21:08:28 -0700 Subject: Cleanup and utils file. --- nomic.moon | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'nomic.moon') 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") -- cgit v1.2.3