From 73757749314c25a57d1c217e6a707df620f14f59 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 23 Dec 2013 20:41:24 -0500 Subject: [PATCH] Added dumptable.lua --- dumptable.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 dumptable.lua diff --git a/dumptable.lua b/dumptable.lua new file mode 100644 index 0000000..d897986 --- /dev/null +++ b/dumptable.lua @@ -0,0 +1,42 @@ +function dumptable(tabname, tab, depth) + if depth == nil then -- first call, before any recursion? + depth = 1 + end + + if tabname ~= nil then + if tab == nil then + print(tabname .. " = nil") + return + else + print(tabname .. " = {") + end + end + + local depthstr = "" + for i=1,(depth*4) do + depthstr = depthstr .. " " + end + + if tab.DUMPTABLE_ITERATED then + print(depthstr .. "(...circular reference...)") + else + tab.DUMPTABLE_ITERATED = true + for k,v in pairs(tab) do + if type(v) == "table" then + print(depthstr .. tostring(k) .. " = {") + dumptable(nil, v, depth + 1) + print(depthstr .. "}") + else + if k ~= "DUMPTABLE_ITERATED" then + print(depthstr .. tostring(k) .. " = " .. tostring(v)) + end + end + end + tab.DUMPTABLE_ITERATED = nil + end + + if tabname ~= nil then + print("}") + end +end +