[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Can I use __gc metamethod directly from Lua?
- From: David Given <dg@...>
- Date: Sun, 26 Nov 2006 01:49:11 +0000
Adam D. Moss wrote:
> Well... having asked about this before, I got the reply that using a
> Lua function as a finalizer is fully supported, IIRC. Certainly I do
> this extensively without conspicuous problems.
Yeah, but setmetatable() doesn't work on userdata, and __gc *only* works on
userdata, which means that in order to do it you have to go via C. Which means
you have to be really serious to do it.
IIRC, Lua follows similar semantics to Java --- finalisers are only ever
called once, which means that if an object is resurrected and then garbage
collected again, it won't be finalised again. (Now I think of it, if your
finaliser is running Lua code it must be briefly resurrected, since 'self'
must be referenced.)
╭─┈David Given┈──McQ─╮ "...electrons, nuclei and other particles are good
│┈ firstname.lastname@example.org┈┈┈┈│ approximations to perfectly elastic spherical
│┈(email@example.com)┈│ cows." --- David M. Palmer on r.a.sf.c
Description: OpenPGP digital signature