From 70ec5254814f9531e5ca2024465d0e01130306b7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 21 Feb 2024 09:28:49 -0600 Subject: Initial commit --- pp.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pp.lua (limited to 'pp.lua') diff --git a/pp.lua b/pp.lua new file mode 100644 index 0000000..3710b07 --- /dev/null +++ b/pp.lua @@ -0,0 +1,36 @@ +--- lam.pp + +local pp = {} + +function pp.dump (x, lvl) + lvl = lvl or 0 + local space = string.rep(" ", lvl) + local output = "" + if type(x) == "table" then + local subo = "" + for k,v in pairs(x) do + if v == x then + v = "self" + else + v = pp.dump(v, lvl+2) + end + subo = subo .. string.format("\n%s[%s] = %s,", + (space.." "), k, v) + end + output = output .. string.format("\n%s{%s\n%s}", + space, subo, space) + else + output = output .. string.format("%s", x) + end + return output +end + +function pp.pp (x) + print(pp.dump(x)) +end + +return setmetatable(pp, { __call = + function(_, x) + return pp.pp(x) + end, +}) -- cgit 1.4.1-21-gabe81