[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANNOUNCE] LTN 6 - Weak references: implementation and use in Lua
- From: Edgar Toernig <froese@...>
- Date: Fri, 30 Mar 2001 22:14:53 +0200
John Belmonte wrote:
> [Umm... before my little message here I have a rant regarding certain posts
> to lua-l. If you find yourself posting a message that consists of 80%
> quoted text, 15% signature and pgp info, and 5% barely Lua-related content,
> please consider looking up some FAQ's on mailing list etiquette.]
IMHO lua-l has very few of these kind of postings. And the best thing to
do is just notify the poster in private and let him read the netiquette ;-)
> Edgar Toernig wrote:
> > Instead of calling
> > the GC method for NIL after garbage collection I added two call-
> > backs. _GC_PREACTION and _GC_POSTACTION.
> Your solution is just as good. By the way, would anything funky happen if a
> gc cycle happened within your hooks?
No, because the garbage collector is disabled while these hooks are executing.
> > One thing I'm still thinking about is adding callbacks for gc'ed
> > refs itself.
> However if you implement low-level callbacks during the gc cycle and export
> this to Lua won't it cause some danger? It falls in the same category as gc
> events for tables.
Not exactly. The references are still alive. Only the objects that the
references point to have been collected. It's basically exactly the same
you did in the nil-gc callback. The reason I did not add it to Sol yet
is that the callback wants the weakref object (a userdata) as its arg.
But that would require an interaction between the garbage collector and
the weakref module. A possible solution would be to only allow C call-
back functions (similar to the call- and line-hook) and then the weakref
module would register this function and can transform the integer reference
to the userdata object. But the module requires some context too and then
this becomes a little bit ugly :-/