lua-users home
lua-l archive

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

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 
>"*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, PUC-Rio
> print(io.lines("tabs"))
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 =
	  data              = f:read("a")

	-- f is closed, and data has the contents.