about summary refs log tree commit diff stats
path: root/dump.lua
diff options
context:
space:
mode:
authorCase Duckworth2024-04-03 22:45:59 -0500
committerCase Duckworth2024-04-03 22:45:59 -0500
commit235026f7d5893be5c3e2307e6dc61424e1aa91d2 (patch)
tree68e86924787d5c13a3dd01f925a703dea2c9eadf /dump.lua
parentProtect evaluation within repl (diff)
downloadlam-235026f7d5893be5c3e2307e6dc61424e1aa91d2.tar.gz
lam-235026f7d5893be5c3e2307e6dc61424e1aa91d2.zip
Change pp -> dump
Keep them 4 letter file name boiiii
Diffstat (limited to 'dump.lua')
-rw-r--r--dump.lua36
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
3local m = {}
4local type = require "type"
5
6function 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
29end
30
31function m.pp (x)
32 print(m.dump(x))
33end
34
35---
36return m