[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: avoiding recursion in a dump_table function
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 10 May 2011 12:50:14 -0300
> function dump_table(t, prefix, seen)
> prefix = prefix or ""
> seen = seen or {}
> if seen[t] then
> print(prefix .. " is recursive")
> else
> seen[t] = t
> local k,v
> for k,v in pairs(t) do
> if(type(v) == "table") then
> dump_table(v, prefix .. k .. ":",seen)
> else
> print(prefix .. k .. "=" .. tostring(v))
> end
> end
> end
> end
This technique is used in http://www.lua.org/cgi-bin/demo?globals