lua-users home
lua-l archive

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


> Is there any tangible notion of what is to become of newproxy() ?
>
> I found it useful today, to add some implicit finalization to objects
> implemented with tables. (After feeling surprised that '__gc' is for
> userdata only.)

__gc is called asynchronously at rather unpredictable points in the
program.  A C extension writer can take that into account (and can
actually do some useful work without invoking the garbage collector),
but it's more difficult to do this in Lua code.  It's also not
possible to create a critical section which locks out the garbage
collector.

It might be better if there was some sort of __gcqueue metatable slot
which referred to an array.  When the object becomes unreachable, it
is added to the __gcqueue array.  Lua functions which interact with
these objects would process the queue.  This way, the side effect
would occur at well-defined points in the program.