[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [proposal] close file on io.lines("filename", "*a")()
- From: "Soni \"They/Them\" L." <fakedme@...>
- Date: Tue, 30 Jul 2019 11:54:56 -0300
On 2019-07-30 11:49 a.m., nobody wrote:
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"
(or something like that) should work, right?
Sometimes it actually makes sense to read '*a' and then seek back and
sometimes you don't wanna leak file descriptors which you can only have
about 1000 or so per user or something I might be off by an order of
magnitude or so but you get the idea.