lua-users home
lua-l archive

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


In your example, does your scope() function absolutely guarantee that the file you opened in the call to scope() will synchronously and reliably be closed after the “end” of the for loop but before the final call to print()?

Doesn’t the closing of the file in your code depend in some way on an asynchronous part of the Lua core, namely the garbage collector?



> On 14 Jun 2019, at 13:16, Sergey Zakharchenko <doublef.mobile@gmail.com> wrote:
> 
> Paul,
> 
>> Why do we need the ugly, weird-looking and controversial <toclose> notation at all?
> 
> Indeed, so many people don't like it, but fail to notice one thing.
> You don't have to use it!
> 
> local function scope(object)
>    return next,{[object]=1},nil,object
> end
> 
> for file in scope(io.open("file")) do
>    print("I can use file ",file)
> end
> 
> print"File has been closed!"
> 
> People trying to get others to use variants of 'with' don't notice
> it's there already.
> 
> Please. Things are going fine.
> 
> Best regards,
> 
> -- 
> DoubleF
>