[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [proposal] close file on io.lines("filename", "*a")()
- From: Sean Conner <sean@...>
- Date: Tue, 30 Jul 2019 13:12:11 -0400
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.