git.s-ol.nu mmm / 5bedc22
protect print/deep_tostring from recursion s-ol 1 year, 11 months ago
2 changed file(s) with 9 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
66 MODE = 'CLIENT'
77 UNSAFE = true
88
9 deep_tostring = (tbl, space='') ->
10 return tbl if 'userdata' == type tbl
9 deep_tostring = (tbl, space='', recur={}) ->
10 buf = space .. tostring tbl
1111
12 buf = space .. tostring tbl
13 return buf unless 'table' == (type tbl) and not tbl.__tostring
12 return buf unless 'table' == (type tbl) and not tbl.__tostring and not recur[tbl]
1413
14 recur[tbl] = true
1515 buf = buf .. ' {\n'
1616 for k,v in pairs tbl
17 buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' '}\n"
17 buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' ', recur}\n"
1818 buf = buf .. "#{space}}"
1919 buf
2020
00 export MODE, print, warn, relative
11 MODE = 'SERVER'
22
3 deep_tostring = (tbl, space='') ->
3 deep_tostring = (tbl, space='', recur={}) ->
44 buf = space .. tostring tbl
55
6 return buf unless 'table' == (type tbl) and not tbl.__tostring
6 return buf unless 'table' == (type tbl) and not tbl.__tostring and not recur[tbl]
77
8 recur[tbl] = true
89 buf = buf .. ' {\n'
910 for k,v in pairs tbl
10 buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' '}\n"
11 buf = buf .. "#{space} [#{k}]: #{deep_tostring v, space .. ' ', recur}\n"
1112 buf = buf .. "#{space}}"
1213 buf
1314