Re: [proposal] close file on io.lines("filename", "*a")()
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: [proposal] close file on io.lines("filename", "*a")()
- From: nobody <nobody+lua-list@...>
- Date: 2019年7月30日 16:49:28 +0200
On 30/07/2019 16.42, Soni "They/Them" L. wrote:
since lua doesn't have refcounting and some ppl wanna do basically
io.open(file):read("*a") I wanna propose io.lines("filename", "*a")()
(or alternatively io.lines("filename", "*a", "*l")) should close the
file as if the iterator ran out.
function readfile( name )
local <toclose> f, err = io.open( name, "r" )
if not f then return nil, err end
return f:read "*a"
end
(or something like that) should work, right?
Sometimes it actually makes sense to read '*a' and then seek back and
read(/write) again…
-- nobody