[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 14:44:04 -0300
On 2019-07-30 2:12 p.m., Sean Conner wrote:
It was thus said that the Great Soni They/Them L. once stated:
> 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.
Lua 5.4 already does that.
Lua 5.4.0 Copyright (C) 1994-2019 Lua.org, PUC-Rio
function: 0x8b39900 nil nil file (0x8b410f8)
That final value marks the descriptor for closing when the iterator is
done. If you want to automatically close the file after reading the
local data do
local <toclose> f = io.open(myfile)
data = f:read("a")
-- f is closed, and data has the contents.
no, sorry, I think you misunderstood.
note the call at the end. this reads the whole file. ideally it'd also