[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: break for iterators
- From: "Ben Sunshine-Hill" <sneftel@...>
- Date: Fri, 22 Feb 2008 11:50:23 -0500
On Fri, Feb 22, 2008 at 11:41 AM, Shmuel Zeigerman <shmuz@actcom.co.il> wrote:
> It isn't wrong, but the "generic for" just terminates the loop on
> breaks, so the file remains open until the garbage collector will close
> it. The following example should work (untested):
>
>
> > for k=1,1000 do
> > for line in io.lines() do
> > break
> > end
> > collectgarbage"collect"
> > end
>
> Wouldn't it be possible to enhance the "generic for" by adding an extra
> "break" call to the iterator (with a nil or false argument), to let it
> do the cleanup when needed? That may break the existing applications
> though (no pun intended).
I would think the easier fix would simply be for io calls which fail
to allocate a file handle to collectgarbage and try again.