lua-users home
lua-l archive

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


On Tue, Jul 21, 2020 at 3:14 PM Dibyendu Majumdar wrote:
One problem with the to-be-closed variable approach is that it exposes
the variable ... so all kinds of issues arise from that.


Yes, hidden to-be-closed variables (in generic-for loops) are very good.
Only visible ones could be misused  :-)

IMO, the "defer" statement is more comfortable than the metamethod.
For example, the following line would be a simple solution:
defer if arg[1] ~= "--log-everything" then logfile:close() end end
But there are reasons why "defer" is not used in Lua.

The problem can be reworded as follows:
Previously in Lua, a dependency was a king.
But a new behavior was introduced, which deliberately ignores dependencies.
A closeable value is being closed despite some Lua objects still referring to the variable.

So, the <close> keyword should be used with caution.
Isn't it the reason for such conspicuous <syntax> ? :-)