diff options
Diffstat (limited to 'dump.lua')
-rw-r--r-- | dump.lua | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/dump.lua b/dump.lua new file mode 100644 index 0000000..dc32096 --- /dev/null +++ b/dump.lua | |||
@@ -0,0 +1,36 @@ | |||
1 | --- lam.pp | ||
2 | |||
3 | local m = {} | ||
4 | local type = require "type" | ||
5 | |||
6 | function m.dump (x, lvl) | ||
7 | lvl = lvl or 0 | ||
8 | local space = string.rep(" ", lvl) | ||
9 | local output = "" | ||
10 | --[[if getmetatable(x) and getmetatable(x).__tostring then | ||
11 | output = output .. tostring(x) | ||
12 | else]]if type.luatype(x) == "table" then | ||
13 | local subo = "" | ||
14 | for k,v in pairs(x) do | ||
15 | if v == x then | ||
16 | v = "self" | ||
17 | else | ||
18 | v = m.dump(v, lvl+2) | ||
19 | end | ||
20 | subo = subo .. string.format("\n%s[%s] = %s,", | ||
21 | (space.." "), k, v) | ||
22 | end | ||
23 | output = output .. string.format("\n%s{%s\n%s}", | ||
24 | space, subo, space) | ||
25 | else | ||
26 | output = output .. tostring(x) | ||
27 | end | ||
28 | return output | ||
29 | end | ||
30 | |||
31 | function m.pp (x) | ||
32 | print(m.dump(x)) | ||
33 | end | ||
34 | |||
35 | --- | ||
36 | return m | ||