lua-users home
lua-l archive

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


On Thu, Jul 14, 2011 at 11:13 AM, KR <krunal.rao78@gmail.com> wrote:
> local function write(array, filename, mode)
>  mode = mode or "w"
>  local f = assert(io.open(filename, mode))
...
> What I am wondering about is mainly whether it's a good practice to pass around
> filenames instead of filedescriptors (handles).

If it works for you. Your implementation above I wouldn't call
write(), I'd call it appendtofile(), write
has several other possible behaviours, depending on the open() flags.

> I was also interested in the motivations that led to prefer for the io library
> the approach of "non-signalling errors" (i.e. nil + error message on error)
> instead of the "signalling" one (error(errormessage) on error).
> I am finding myself surrounding (almost) all the io operations with asserts,
> while with the signalling approach this would not be necessary and if action can
> be taken to recover from the error this action can be implemented via pcall.
> It's not a critique, I am just curious =)

Its a good question, and answered here:

http://lua-users.org/wiki/FinalizedExceptions

Cheers,
Sam