lua-users home
lua-l archive

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

David Given wrote:
I'd just like to point out that the various Java people we have here will, if you mention finalisers to them, start frothing at the mouth and using phrases like 'utterly brain-damaged', 'my god, what were they thinking', 'spawn of satan' and in some circumstances 'eeeeeeeaaaaaagh'.

Just think about these:

        oo = o

Tell me if this solution has any holes - I presume it must because it seems straightforward and simple - within a finaliser, make it illegal for the object undergoing finalisation to be on the right hand side of an assignment operation. Off the top of my head, this could be implemented by adding an extra field to lua_State that indicates which object, if any, is undergoing finalisation, and then modifying the load and move op codes so they won't allow the object under finalisation to be on the right hand side. This would admittedly slow down the VM slightly - does the parser have enough information to do thisat compile time, rather than run time? Care may be required to ensure that finalisers are called respecting hierarchy and that members for tables aren't marked for finalisation until the finaliser has completed, however.

Lua gets away with __gc because it has very restricted functionality; finalisers can only be written in C, the finalised objects can't be resurrected, the finalisers can't block, etc. IMO, this is a Very Good Thing.

I can think of a few audit trail purposes where finalisers would be nice, and these could benefit from relaxing the C requirement. Currently one is limited into using work arounds and hacks to abuse metadata values to invoke finalisers. Providing the functionality, even if the documentation has a big "DO NOT USE" sign attached, would simplify and standardise such routines, making them more difficult to break for the uninitiated.

Sorry for rambling, and sorry for jumping in :)