[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Bugs.. ? (was: Re: Lua-users standard libraries project: anyone game?)
- From: "Virgil Smith" <Virgil@...>
- Date: Wed, 28 Jan 2004 15:06:35 -0600
> > o std.base.lua:tostring need to check for
> > self referencing tables, or it goes down
> > an endless circle of tostring calls.
>
> Thanks. I had fun trying to fix this.
> I have committed the result, which
> seems to work for things like
>
> a = {}; a[1]=a; print(a)
> a = {{}}; a[1][1]=a; print(a)
> a = {}; b = {a}; a[1] = b; print (a)
> a = {}; b = {a,a}; print (b)
I've hit the cyclical reference issue before (in a utility for saving "data"
from scripts). What I came up with was making a temporary table to hold
references to any reference based objects (i.e. tables, userdata, functions,
and threads). In this table the references are the keys and I used an
incremented integer for assigning values. Thus when you come to a table (or
other object) all you need to do is check for it in the table.
In my "data" file I'd then just record the integer ID "reference" in place
of the whole object. I'm not sure what you would present best in "print"
function, but at least you can avoid the endless recursion.
Ain't it great that you can key off of <anything> in Lua tables. :-)