[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Is breaking out of io.lines(file) safe?
- From: Michal Kottman <k0mpjut0r@...>
- Date: Sun, 20 Mar 2011 20:16:40 +0100
On Sun, 2011-03-20 at 18:59 +0000, Matthew Wild wrote:
> On 20 March 2011 17:41, Matthias Kluwe <firstname.lastname@example.org> wrote:
> > Look at the following simple example:
> > local function f( ... )
> > local of = io.open( 'x.txt', 'w' )
> > of:write( ... )
> > end
> I think it's especially wise to be careful when dealing with files
> opened with "w".
I use the following "rule of thumb" for dealing with files: when dealing
with opening a lot of files (like in a for loop), I close the files by
myself using f:close(), otherwise I leave it to Lua GC.
This way, I can can expect that if I break the loop using Ctrl+C to
check the progress, the files will be filled with some data at least.