aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mmm/init.client.moon10
-rw-r--r--mmm/init.server.moon7
2 files changed, 9 insertions, 8 deletions
diff --git a/mmm/init.client.moon b/mmm/init.client.moon
index 5fb3450..25c7da0 100644
--- a/mmm/init.client.moon
+++ b/mmm/init.client.moon
@@ -7,15 +7,15 @@ window = js.global
MODE = 'CLIENT'
UNSAFE = true
-deep_tostring = (tbl, space='') ->
- return tbl if 'userdata' == type tbl
-
+deep_tostring = (tbl, space='', recur={}) ->
buf = space .. tostring tbl
- return buf unless 'table' == (type tbl) and not tbl.__tostring
+ return buf unless 'table' == (type tbl) and not tbl.__tostring and not recur[tbl]
+
+ recur[tbl] = true
buf = buf .. ' {\n'
for k,v in pairs tbl
- buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' '}\n"
+ buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' ', recur}\n"
buf = buf .. "#{space}}"
buf
diff --git a/mmm/init.server.moon b/mmm/init.server.moon
index fbce18f..0e3534b 100644
--- a/mmm/init.server.moon
+++ b/mmm/init.server.moon
@@ -1,14 +1,15 @@
export MODE, print, warn, relative
MODE = 'SERVER'
-deep_tostring = (tbl, space='') ->
+deep_tostring = (tbl, space='', recur={}) ->
buf = space .. tostring tbl
- return buf unless 'table' == (type tbl) and not tbl.__tostring
+ return buf unless 'table' == (type tbl) and not tbl.__tostring and not recur[tbl]
+ recur[tbl] = true
buf = buf .. ' {\n'
for k,v in pairs tbl
- buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' '}\n"
+ buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' ', recur}\n"
buf = buf .. "#{space}}"
buf