lua-users home
lua-l archive

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


Very nice.

I particularly like the way the open, close, and error checking baggage are 
all wrapped up and tucked away into one function.

No need to add this to the 'io' lib.  The user may want to customize it to 
make the error messages more verbose, or add another 'for' loop to handle a 
list of files like Perl's magical  while( <> ).

Thanks,

- Peter

On Wednesday 12 June 2002 08:18, Roberto wrote:
> I think a good solution would be something like
>
>   function lines (filename)
>     local f = assert(io.open(filename, "r"))
>     return function ()
>       return f:read() or (assert(f:close()) and nil)
>     end
>   end
>
> so that we could use it without any other "preparation":
>
>   for line in lines(file) do ... end
>
> But I'm not sure whether such function belongs to the `io' lib or to
> some extension library.
>
> -- Roberto