aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2019-12-18 15:27:51 +0000
committers-ol <s-ol@users.noreply.github.com>2019-12-18 15:27:51 +0000
commit5bedc226eae70e557746428830f7b583f892a864 (patch)
tree6fa77a16ff203e1bb429f60feb91cdbd3c84b572
parentcites plugin (diff)
downloadmmm-5bedc226eae70e557746428830f7b583f892a864.tar.gz
mmm-5bedc226eae70e557746428830f7b583f892a864.zip
protect print/deep_tostring from recursion
-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