lua-users home
lua-l archive

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


I just noticed that file:write() returns true on success (though the
manual doesn't mention any return value). If it were changed to return
the file, you could write:
> assert(io.open('foo', 'a+')):write('foooo'):close()

instead of:
> local file = assert(io.open('foo', 'a+'))
> file:write('foooo')
> file:close()

One simple change allows for much shorter, neater code... seems pretty
Lua-ish to me! :) Other file methods such as file:flush() and
file:setvbuf() could benefit from the same change. file:seek() as
well, but then you'd be breaking the API (you'd have to return file
and position instead of just position). file:read() maybe if you have
some "read into a table" or "pass the read data to a callback
function", but now we're getting kind of out there... :)

-- 
Sent from my toaster.