From c3e3a9b829fa79ff690b97223a899534fec89ea9 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 23 Jan 2008 20:11:44 +0000 Subject: 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 --- lib/debugs.lua | 87 +++++++++++++++++++--------------------------------------- 1 file 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: -function variables ( view ) - debuginfo = [[ - -

DEBUG INFO: THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES

- ------------ START DEBUG INFORMATION ------------
]] - - --print ("") - for a,b in pairs(view) do - if not (type(b) == "table") then - debuginfo = debuginfo .. "" .. a .. ": >" .. b .. "<
" - else - debuginfo = debuginfo .. "" .. a .. ":...
" - for c,d in pairs(view[a]) do - if not (type(d) == "table") then - debuginfo = debuginfo .. " { " .. c .. ": >" .. d .. "< }
" - else - debuginfo = debuginfo .. " { " .. c .. ":...
" - for e,f in pairs(view[a][c]) do - if not (type(f) == "table") then - debuginfo = debuginfo .. " { { " .. e .. ": >" .. f .. "< } }
" - else - debuginfo = debuginfo .. " { { " .. e .. ":...
" - for g,h in pairs(view[a][c][e]) do - if not (type(h) == "table") then - debuginfo = debuginfo .. " { { { " .. g .. ": >" .. h .. "< } } }
" - else - debuginfo = debuginfo .. " { { { " .. g .. ":...
" - for i,j in pairs(view[a][c][e][g]) do - if not (type(j) == "table") then - debuginfo = debuginfo .. " { { { { " .. i .. ": >" .. j .. "< } } } }
" - else - debuginfo = debuginfo .. " { { { " .. i .. ":...
" - for k,l in pairs(view[a][c][e][g][i]) do - if not (type(l) == "table") then - debuginfo = debuginfo .. " { { { { { " .. i .. ": >" .. l .. "< } } } } }
" - end - end - end - end - end - end - end - end - end - end +function serialize ( view, cnt ) + if type(view) == "string" then + io.write(" >") + io.write(string.format("%q", view)) + io.write("<") + elseif type(view) == "number" then + io.write(" >") + io.write(view) + io.write("<") + elseif type(view) == "table" then + cnt = cnt + 1 +-- io.write("
") + for k,v in pairs(view) do + io.write("
") + io.write(string.rep("{ ",cnt), "", k, "") + 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 ------------
" - return debuginfo end -function serialize(vars) - io.write("
\n")
-	io.write(session.serialize("", vars))
-	io.write("\n
") +function variables ( view ) + io.write [[ + +

DEBUG INFO: THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES

+ ------------ START DEBUG INFORMATION ------------
]] + serialize(view,0) + io.write( "

------------ END DEBUG INFORMATION ------------
") + return end - -- cgit v1.2.3