about summary refs log tree commit diff stats
path: root/pp.lua
diff options
context:
space:
mode:
authorCase Duckworth2024-02-21 09:28:49 -0600
committerCase Duckworth2024-02-21 09:28:49 -0600
commit70ec5254814f9531e5ca2024465d0e01130306b7 (patch)
tree45a4d49115eca436a8467ce4cebfc8cee1f6f9c6 /pp.lua
downloadlam-70ec5254814f9531e5ca2024465d0e01130306b7.tar.gz
lam-70ec5254814f9531e5ca2024465d0e01130306b7.zip
Initial commit
Diffstat (limited to 'pp.lua')
-rw-r--r--pp.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/pp.lua b/pp.lua new file mode 100644 index 0000000..3710b07 --- /dev/null +++ b/pp.lua
@@ -0,0 +1,36 @@
1--- lam.pp
2
3local pp = {}
4
5function pp.dump (x, lvl)
6 lvl = lvl or 0
7 local space = string.rep(" ", lvl)
8 local output = ""
9 if type(x) == "table" then
10 local subo = ""
11 for k,v in pairs(x) do
12 if v == x then
13 v = "self"
14 else
15 v = pp.dump(v, lvl+2)
16 end
17 subo = subo .. string.format("\n%s[%s] = %s,",
18 (space.." "), k, v)
19 end
20 output = output .. string.format("\n%s{%s\n%s}",
21 space, subo, space)
22 else
23 output = output .. string.format("%s", x)
24 end
25 return output
26end
27
28function pp.pp (x)
29 print(pp.dump(x))
30end
31
32return setmetatable(pp, { __call =
33 function(_, x)
34 return pp.pp(x)
35 end,
36})