lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

yep, I thought again about my reply this week-end, and I realized as well.

> -----Original Message-----
> From: Jeff Petkau []
> Sent: vendredi 6 septembre 2002 20:40
> To: Multiple recipients of list
> Subject: RE: Light User Data
> Benoit Germain's clever idea:
> > I keep in the registry a unicity table where a key is a light
> > userdata with the pointer value, and the value is the 'heavy'
> > userdata with the same pointer. Each time I need to provide a
> > LUA script with a 'heavy' userdata (so that the variable has
> > a metatable and its methods can be accessed), I lookup the
> > light pointer value in the registry and fetch the corresponding
> > 'heavy' userdata. If I don't find it I add it. That way, for
> > each resource instance the library can provide there is always
> > exactly one 'heavy' userdata that references it.
> ...
> > Of course, this reference in the unicity table means that this
> > 'heavy' userdata can never be garbage collected unless some
> > destroy mechanism is explicitly invoked by the script, in which
> > case the unicity table entry is cleared.
> If you want to allow the heavy userdatas to be garbage
> collected, you could just give your registry a metatable
> with weakmode="v".
> --Jeff