[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Object references from user data
- From: RLake@...
- Date: Mon, 4 Aug 2003 09:46:37 -0500
Mark Hamburg preguntó:
> How complicated would it be to allow userdata to consist of two
> The first section would be a series of TObjects of a length generally
> specified in the userdata constructor. The rest of the object would
> of arbitrary data as it does now. Even better would be a way to specify
> offset and count for the pointers so that one could position them a bit
> freely, but this comes with extra overhead. The garbage collector could
> trace the references from a user data just as it traces references from
As I understand it, the difficulty here is handling finalizers for
The current finalizer implementation assumes that userdata have no Lua
references, so there cannot be circular references between finalizable
This is really a problem of semantics: what should a finalizer do when
confronted with a collection of inter-referencing objects? There does
not seem to be any good answer to this question.
Leaving that aside, there is a fairly simple way of letting a userdata
get at a collection of Lua objects: put the Lua objects in the userdata's
metatable. Of course, this means creating a unique metatable for each
userdata, which is a bit of overhead. But if you use integer keys
starting from 0 or 1, it is not too much overhead.