lua-users home
lua-l archive

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


On Thu, 6 Jun 2019 at 17:10, Sergey Zakharchenko
<doublef.mobile@gmail.com> wrote:
> There's a very simple use case documented right in the 5.4 manual for an object that might have no references to it visible from Lua (and possibly from any C function Lua may call), yet it has to live to see its its metamethod __close called at the right time. Look at the generic for loop.
>
> The answer to my question cannot be 'no', that's the point:).
>

Hi, I don't know if I understood the point here so forgive me if I didn't.

I think you are saying that if a variable is marked 'toclose' and has
a __toclose() method then Lua must _guarantee_ the execution of the
__toclose() method when the variable goes out of scope, regardless of
GC.

If I understood you correctly then it seems a valid requirement. In
languages such as Java this problem doesn't arise because one writes
like this:

Resource r = null;
try {
   r = acquire();
}
finally {
   if (r != null)
      r.close();
}

So by the very structure the variable is alive at the time of cleanup.

Regards