about summary refs log tree commit diff stats
path: root/dump.lua
diff options
context:
space:
mode:
authorCase Duckworth2024-04-09 21:04:17 -0500
committerCase Duckworth2024-04-09 21:04:29 -0500
commit8ce2915e3c54598c2fda4fec0980ebfc2a3adf6e (patch)
tree124ef31663ed570bed358dffd9c861d10fabce7b /dump.lua
parentUh (diff)
downloadlam-8ce2915e3c54598c2fda4fec0980ebfc2a3adf6e.tar.gz
lam-8ce2915e3c54598c2fda4fec0980ebfc2a3adf6e.zip
Reorganization
Diffstat (limited to 'dump.lua')
-rw-r--r--dump.lua39
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
3local m = {} 3local m = {}
4local type = require "type" 4local type = require("type")
5 5
6function m.dump (x, lvl) 6function 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)
29end 30end
30 31
31function m.pp (x) 32--------
32 print(m.dump(x))
33end
34
35---
36return m 33return m