lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




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"
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


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.