lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote:

Or actually, a step better than that - abstract the whole lot so it's
easy for people to create IO methods that use the same interface?


That would be nice. Suggestions?

I'm no software engineer, but what about something along the lines of the handle returned by io.open() or user-provided functions for other types of file be a table, with a "handle" field that can be anything the supporting library wants to put in it (a userdata with a FILE* or fd in it, or a table with two handles in it, for bidirectional pipes, and such), and then functions with names similar to the io. interface (read, write, close, and such) that the io. functions call to do the work.

I'm sure there are more elegant ways of doing it, but this way would certainly be simple to use.

Something I've always pined to be able to do is handle[n] to get the nth byte, or similar, which could then be easily added yourself if you wanted.

On an semi-unrelated note, is there a nice way, or 'standard' interface for getting slices out of types? (ie, t[4..6] on a table returns a new table with entries 4 to 6 from t, or s[10..90] to get that range from a string?)

--
Rob Kendrick, Pepperfish Ltd.         +44 (0)845 226 4146  www.pepperfish.net
PGP signed or encrypted mail welcome                         Key ID: 3651D17A