lua-users home
lua-l archive

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


Here’s something I don’t understand.

Why do we need the ugly, weird-looking and controversial <toclose> notation at all? (Also, “toclose” isn’t quite the right word anyway, but that is another matter.)

We don’t annotate variable declarations with <tofinalize> when they have a finalizer - we just set a __gc metamethod and that tells Lua it’s a <tofinalize> variable automatically.

A <toclose> variable *must have* a __close metamethod or else an error is raised when it goes out of scope. So why can’t the presence of a __close metamethod be the signal to Lua that it is handling a to-be-closed variable?

The <toclose> flag for a variable should simply be set automatically at runtime when the setmetatable() function is called for the variable.



PS. The __close metamethod is not documented in the Metatables and Metamethods section (2.4) of the manual. It should be. (The __gc metamethod is mentioned there but as a bit of an afterthought. Both of those special metamethods ought to be included in the formal list of events that activate metamethods, for completeness and clarity.)