This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
api:buffer [2016/06/19 05:49] payonel [Interface Methods] |
api:buffer [2016/06/19 05:56] payonel [Instance Methods] |
||
---|---|---|---|
Line 62: | Line 62: | ||
| | ||
Each `format` is read from the stream and all returned in a multiple return value list of the results. Note all format strings are prefixed with \* and also note that only the first char of the string names of the formats matters, the rest is ignored. These are the supported formats: | Each `format` is read from the stream and all returned in a multiple return value list of the results. Note all format strings are prefixed with \* and also note that only the first char of the string names of the formats matters, the rest is ignored. These are the supported formats: | ||
- | ``` | ||
- | local file = io.open( | ||
- | ``` | ||
* a number value, e.g. `b:read(10)` | * a number value, e.g. `b:read(10)` | ||
Line 127: | Line 124: | ||
The following methods are expected to be implemented on the buffered streams passed to `buffer.new`. | The following methods are expected to be implemented on the buffered streams passed to `buffer.new`. | ||
- | - `close()` | + | - `close() ok, reason` |
+ | |||
+ | Close handles, release resources, disconnect -- and return success | ||
+ | |||
+ | - `write(arg: string) ok, reason` | ||
- | Close handles, release resources, disconnect -- and return success | + | Write `arg` as bytes, assume a string of plain unformatted chars. Return falsey and reason on failure. |
- | - `write(arg: string)` | + | |
- | Write `arg` as bytes, assume a string of plain unformatted chars. Return falsey and reason on failure. | + | - `read(n: number) ok, reason` |
- | - `read(n: number)` | + | |
- | Return `n` unicode chars. The caller assumes there is more data to read until `nil` is returned. A empty string, or a string shorter than `n` chars long, is a valid return, but the caller may assume there is more data to request until `nil` is returned. | + | Return `n` unicode chars. The caller assumes there is more data to read until `nil` is returned. A empty string or a string shorter than `n` chars long is a valid return, but the caller may assume there is more data to request until `nil` is returned. |
- | - `seek([whence: string], [offset: number)` | + | - `seek([whence: string], [offset: number]) [offset from start] or falsey, reason` |
- | Refer to `b:seek()` for details. In short, move the stream position to `offset` from `whence`, and return the `offset` from the start of the stream of the position after the seek operation. Note that `seek("cur", 0)` is a valid request, typical of the caller wanting to determine the current position of the stream. Your stream is not required to support `seek`, in such case (or in any case of failure) you should return nil, and the reason (as a string) for the failure. | + | Refer to `b:seek()` for details. In short, move the stream position to `offset` from `whence`, and return the `offset` from the start of the stream of the position after the seek operation. Note that `seek("cur", 0)` is a valid request, typical of the caller wanting to determine the current position of the stream. Your stream is not required to support `seek`, in such case (or in any case of failure) you should return nil, and the reason (as a string) for the failure. |