[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Suggestion: file:write() and other methods should return file
- From: HyperHacker <hyperhacker@...>
- Date: Sat, 2 Jul 2011 04:53:48 -0600
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.