[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: GC method for objects
- From: "Adam D. Moss" <adam@...>
- Date: Tue, 19 Apr 2005 15:04:07 +0100
(following-up to myself...)
Adam D. Moss wrote:
A simpler way is to store the dummy created-on-demant heavyuserdata
directly in your {}, using a reserved key (e.g., __userdata).
That's possible but pollutes the original table (but that
might not be a problem for objects, where you wouldn't
usually for example want to do a pairs() over the table).
Oh of course, silly me; most ways of actually implementing
objects and classes use a proxy table so pairs() doesn't
work properly anyway.
You then need a way to map back from the userdata to the table
Since this userdata is dummy anyway, you can store the table as the
userdata's metatable.
That's a very nice idea (though then, surely, the __gc field has
to go into the table itself and the same pollution occurs as above).
The table itself could go inside the userdata's metatable somewhere
(creating a loop, but oh well). The penalty is that this removes
the ability to share this metatable between all such userdata.
--Adam
--
Adam D. Moss - adam@gimp.org