[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: Sat, 22 Jun 2019 22:32:41 +0100
>>>>> "Patrick" == Patrick Donnelly <batrick@batbytes.com> writes:
>> In 5.4, io.lines explicitly _does_ integrate with the generic for
>> loop to ensure the file is closed (if it was opened and isn't just
>> using io.input). What makes you think there is not?
Patrick> Sorry, I meant that there is no integration with generic for
Patrick> loop and the toclose variables, i.e. that breaking out of the
Patrick> for loop will cause the state value to be closed.
But this integration does exist. Why do you think it does not?
The generic for loop in 5.4 takes 4 values, not 3, and the 4th one is
treated as being assigned to a toclose variable. That is to say,
for foo in a,b,c,d do ... done
will invoke d's __close metamethod when the loop is exited by any means.
io.lines("file") now returns 4 values: readline_func, nil, nil, file
where the readline_func is a closure that returns the next line from the
file, and "file" is the filehandle that was opened, which will be closed
via its __close metamethod.
--
Andrew.