lua-users home
lua-l archive

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


And I should perhaps have mentioned the more general patterns:

	io.with_openfile_do( filepath, function( file )
		-- do stuff
	end )

And

	io.with_newfile_do( filepath, function( file )
		-- do stuff
	end )

The former opens the file if it already exists and hands it to the function for processing. The latter creates the file and hands it to the function for processing. If the function fails, it deletes the file.

So, a couple of questions to ask are:

* How expensive is it to generate the closures that this sort of style promotes?

* Are the cases where we need to do this sufficiently rare that they are simply the job of the library writer or are they going to be common enough and ad hoc enough that library writers are unlikely to cover them all?

Mark