lua-users home
lua-l archive

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


On Mon, Apr 3, 2017 at 2:34 PM, Gé Weijers <ge@weijers.org> wrote:
> I'm not against adding features to improve the early releasing of resources,
> but adding a C# style 'using' clause or similar only fixes a part of the
> problem. This one leaks too:
>
> for line in io.lines("myfile")
> do
>   if pattern:match(line) then break end
> end
>
> io.lines only closes the file if it hits the end of file, or when the
> garbage collector catches up with the abandoned file. Is there a way to
> catch cases like this as well? I don't know, but it would be nice to
> consider any options before copying an existing solution from C#/Go/Scheme
> or whatever other language there is.

Well with the introduction of block scope finalization, Lua would
simultaneously adapt generic-for to have block scope finalization of
the state var (and possibly even the other hidden locals in the
generic-for).

-- 
Patrick Donnelly