[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.4.0 (alpha) now available
- From: Andrew Gierth <andrew@...>
- Date: Fri, 21 Jun 2019 21:52:40 +0100
>>>>> "Soni" == Soni \"They/Them\" L <fakedme@gmail.com> writes:
>> You do realize that this is one of the primary reasons for 'toclose'
>> to exist at all? The fact that breaking or erroring out of a loop
>> doesn't give the iterator any chance to clean up is a significant
>> problem (for example, if iterating over io.lines, the file is not
>> closed until it is GC'd, which may not happen until much later).
Soni> I'm convinced <toclose> should support nested contexts (read:
Soni> have an __enter).
Soni> I have, many times, used file:lines() (which is more like
Soni> file:read_iter() because you can give it args) in a loop that I
Soni> would break out of, and then I'd use the file some more.
Looping on file:lines doesn't close the file at the end of the loop, so
it doesn't close it on break/error either. Only io.lines does that, and
only when not reading from io.input.
--
Andrew.