[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: avoiding recursion in a dump_table function
- From: Peter Cawley <lua@...>
- Date: Tue, 10 May 2011 16:48:16 +0100
On Tue, May 10, 2011 at 4:46 PM, Dave Collins
<Dave.Collins@mercatustechnologies.com> wrote:
>> 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
>
> Cool. What do I pass to this param 'seen'?
Nothing; the first two lines provide the default values for 'prefix'
and 'seen' (though you can provide 'prefix' if you want to).