lua-users home
lua-l archive

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

> The chief difficulty is that an object referenced by such a variable can be
> assigned to another variable (stored in a table, captured in a closure),
> and vice versa. And, if that is not prevented, then the other variable may
> end up holding a reference to a finalized object. Today's resurrection
> could also result in that, but today resurrection is fully controlled by
> the finalizer and hence its library's writer; changing that will make a lot
> of existing libraries invalid.

I think it is a good practice to allow objects to be "finalized"
multiple times (that is, to allow their __gc metamethod to be called
multiple times) and also to allow references to finalized objects with
sensible behavior.

First, if the library does not protect metatables, any code can get the
__gc metamethod and call it explicitly. Second, it is a good practice
(well, I think it is) to provide an explicit way to "close" an object
that needs finalization.

The io library, for instance, does that.

-- Roberto