lua-users home
lua-l archive

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


On Sun, 2011-03-20 at 18:59 +0000, Matthew Wild wrote:
> On 20 March 2011 17:41, Matthias Kluwe <mkluwe@gmail.com> 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.