aboutsummaryrefslogtreecommitdiff
path: root/utils.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-10-13 18:09:04 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-10-13 18:09:04 -0700
commite476bfea5261b04e32cd444208bbffa34bc6f475 (patch)
tree1e298777e70f50e9fb7625b45395d8c5c4c91e38 /utils.moon
parentd13bcde2b9306e0c87b055faed88da76bd3ff41e (diff)
Improved code generation for "when" statements using elseif, and
improved code generation for loops by omitting goto labels when not used.
Diffstat (limited to 'utils.moon')
-rw-r--r--utils.moon7
1 files changed, 4 insertions, 3 deletions
diff --git a/utils.moon b/utils.moon
index 9cceaac..7d1e39e 100644
--- a/utils.moon
+++ b/utils.moon
@@ -138,15 +138,16 @@ utils = {
comparison = if reverse then ((x,y)->(keyFn(x)>keyFn(y))) else ((x,y)->(keyFn(x)<keyFn(y)))
table.sort list, comparison
- equivalent: (x,y)->
+ equivalent: (x,y,depth=1)->
if x == y then return true
if type(x) != type(y) then return false
if type(x) != 'table' then return false
+ if depth == 0 then return false
for k,v in pairs(x)
- if y[k] != v
+ unless utils.equivalent(y[k], v, depth-1)
return false
for k,v in pairs(y)
- if x[k] != v
+ unless utils.equivalent(x[k], v, depth-1)
return false
return true