Added maxdepth to luci.util.dumptable
This commit is contained in:
parent
af2cce3839
commit
8b28f46eea
1 changed files with 4 additions and 4 deletions
|
@ -183,18 +183,18 @@ end
|
||||||
|
|
||||||
--- Recursively dumps a table to stdout, useful for testing and debugging.
|
--- Recursively dumps a table to stdout, useful for testing and debugging.
|
||||||
-- @param t Table value to dump
|
-- @param t Table value to dump
|
||||||
-- @param i Number of tabs to prepend to each line
|
-- @param maxdepth Maximum depth
|
||||||
-- @return Always nil
|
-- @return Always nil
|
||||||
function dumptable(t, i, seen)
|
function dumptable(t, maxdepth, i, seen)
|
||||||
i = i or 0
|
i = i or 0
|
||||||
seen = seen or setmetatable({}, {__mode="k"})
|
seen = seen or setmetatable({}, {__mode="k"})
|
||||||
|
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
perror(string.rep("\t", i) .. tostring(k) .. "\t" .. tostring(v))
|
perror(string.rep("\t", i) .. tostring(k) .. "\t" .. tostring(v))
|
||||||
if type(v) == "table" then
|
if type(v) == "table" and i < maxdepth then
|
||||||
if not seen[v] then
|
if not seen[v] then
|
||||||
seen[v] = true
|
seen[v] = true
|
||||||
dumptable(v, i+1, seen)
|
dumptable(v, maxdepth, i+1, seen)
|
||||||
else
|
else
|
||||||
perror(string.rep("\t", i) .. "*** RECURSION ***")
|
perror(string.rep("\t", i) .. "*** RECURSION ***")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue