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