From 8ce2915e3c54598c2fda4fec0980ebfc2a3adf6e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 9 Apr 2024 21:04:17 -0500 Subject: Reorganization --- dump.lua | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'dump.lua') diff --git a/dump.lua b/dump.lua index dc32096..538f606 100644 --- a/dump.lua +++ b/dump.lua @@ -1,36 +1,33 @@ ---- lam.pp +--- lam.dump --- dump raw lua values local m = {} -local type = require "type" +local type = require("type") function m.dump (x, lvl) lvl = lvl or 0 - local space = string.rep(" ", lvl) - local output = "" - --[[if getmetatable(x) and getmetatable(x).__tostring then - output = output .. tostring(x) - else]]if type.luatype(x) == "table" then - local subo = "" - for k,v in pairs(x) do + local space = string.rep(" ", lvl*4) + local out = {} + if type.luatype(x) == "table" then + local sub = {} + for k, v in pairs(x) do if v == x then v = "self" + elseif type.lamtype(v) == "environment" then + v = tostring(v) else - v = m.dump(v, lvl+2) + v = m.dump(v, lvl+1) end - subo = subo .. string.format("\n%s[%s] = %s,", - (space.." "), k, v) + table.insert(sub, + string.format("\n%s[%s] = %s,", space, k, v)) end - output = output .. string.format("\n%s{%s\n%s}", - space, subo, space) + table.insert(out, + string.format("\n%s{%s\n%s}", + space, table.concat(sub), space)) else - output = output .. tostring(x) + table.insert(out, tostring(x)) end - return output + return table.concat(out) end -function m.pp (x) - print(m.dump(x)) -end - ---- +-------- return m -- cgit 1.4.1-21-gabe81