summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-23 20:11:44 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-23 20:11:44 +0000
commitc3e3a9b829fa79ff690b97223a899534fec89ea9 (patch)
tree9443367e5dfadefd62fa0ac9b5566353b0b55ec2 /lib
parent112fc74c0dd3c36ed8775ece069383e05a299397 (diff)
downloadacf-core-c3e3a9b829fa79ff690b97223a899534fec89ea9.tar.bz2
acf-core-c3e3a9b829fa79ff690b97223a899534fec89ea9.tar.xz
Cleaning up debugs code and making it work better with tables that are nested multiple times.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@630 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r--lib/debugs.lua87
1 files changed, 28 insertions, 59 deletions
diff --git a/lib/debugs.lua b/lib/debugs.lua
index f8aeb89..9ff9e9d 100644
--- a/lib/debugs.lua
+++ b/lib/debugs.lua
@@ -3,68 +3,37 @@
module(..., package.seeall)
require("session")
+--local cnt = 0
--- This will show all tables and their values as debug information
---
--- USAGE: <?
--- USAGE: require("debugs")
--- USAGE: io.write(debugs.variables(view))
--- USAGE: ?>
-function variables ( view )
- debuginfo = [[
- <span style='color:#D2691E;font-family:courier;'>
- <h2>DEBUG INFO: THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2>
- ------------ START DEBUG INFORMATION ------------<BR>]]
-
- --print ("<span style='color:darkblue;font-family:courier;'>")
- for a,b in pairs(view) do
- if not (type(b) == "table") then
- debuginfo = debuginfo .. "<b>" .. a .. "</b>: ><span2 style='color:black'>" .. b .. "</span2><<BR>"
- else
- debuginfo = debuginfo .. "<b>" .. a .. "</b>:...<BR>"
- for c,d in pairs(view[a]) do
- if not (type(d) == "table") then
- debuginfo = debuginfo .. "<b> { " .. c .. "</b>: ><span2 style='color:black'>" .. d .. "</span2>< <B> }</B><BR>"
- else
- debuginfo = debuginfo .. "<b> { " .. c .. "</b>:...<BR>"
- for e,f in pairs(view[a][c]) do
- if not (type(f) == "table") then
- debuginfo = debuginfo .. "<b> { { " .. e .. "</b>: ><span2 style='color:black'>" .. f .. "</span2>< <B> } }</B><BR>"
- else
- debuginfo = debuginfo .. "<b> { { " .. e .. "</b>:...<BR>"
- for g,h in pairs(view[a][c][e]) do
- if not (type(h) == "table") then
- debuginfo = debuginfo .. "<b> { { { " .. g .. "</b>: ><span2 style='color:black'>" .. h .. "</span2>< <B> } } }</B><BR>"
- else
- debuginfo = debuginfo .. "<b> { { { " .. g .. "</b>:...<BR>"
- for i,j in pairs(view[a][c][e][g]) do
- if not (type(j) == "table") then
- debuginfo = debuginfo .. "<b> { { { { " .. i .. "</b>: ><span2 style='color:black'>" .. j .. "</span2>< <B> } } } }</B><BR>"
- else
- debuginfo = debuginfo .. "<b> { { { " .. i .. "</b>:...<BR>"
- for k,l in pairs(view[a][c][e][g][i]) do
- if not (type(l) == "table") then
- debuginfo = debuginfo .. "<b> { { { { { " .. i .. "</b>: ><span2 style='color:black'>" .. l .. "</span2>< <B> } } } } }</B><BR>"
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
+function serialize ( view, cnt )
+ if type(view) == "string" then
+ io.write(" ><span2 style='color:black'>")
+ io.write(string.format("%q", view))
+ io.write("</span2><")
+ elseif type(view) == "number" then
+ io.write(" ><span2 style='color:black'>")
+ io.write(view)
+ io.write("</span2><")
+ elseif type(view) == "table" then
+ cnt = cnt + 1
+-- io.write("<BR>")
+ for k,v in pairs(view) do
+ io.write("<br>")
+ io.write(string.rep("{ ",cnt), "<B>", k, "</B>")
+ serialize(v, cnt)
end
- a,b,c,d,e,f,g,h,i,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil
+-- io.write("}\n")
+ else
+ error("Cannot serialize a " .. type(view))
end
- debuginfo = debuginfo .. "------------ END DEBUG INFORMATION ------------</span>"
- return debuginfo
end
-function serialize(vars)
- io.write("<pre>\n")
- io.write(session.serialize("", vars))
- io.write("\n</pre>")
+function variables ( view )
+ io.write [[
+ <span style='color:#D2691E;font-family:courier;'>
+ <h2>DEBUG INFO: THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2>
+ ------------ START DEBUG INFORMATION ------------<BR>]]
+ serialize(view,0)
+ io.write( "<BR><BR>------------ END DEBUG INFORMATION ------------</span>")
+ return
end
-