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:54] payonel [Interface Methods] |
api:buffer [2016/06/19 07:50] payonel [Instance Methods] |
||
---|---|---|---|
Line 47: | Line 47: | ||
- `b:lines([line_formats...]) string array` | - `b:lines([line_formats...]) string array` | ||
- | Returns a function iterator which reads from the stream until it reaches nil. On each read, the `line_formats` list of args ais passed to `stream:read(...)`. The overwhelmingly typical use is to not define `line_formats`, i.e. passing no args to `lines()`. The default behavior (i..e without `line_formats`) is to read a "line" at a time from the stream. | + | Returns a function iterator which reads from the stream until it reaches nil. On each read, the `line_formats` list of args as passed to `stream:read(...)`. The overwhelmingly typical use is to not define `line_formats`, i.e. passing no args to `lines()`. The default behavior (i..e without `line_formats`) is to read a "line" at a time from the stream. |
```lua | ```lua | ||
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. `10` |
- | Read **n** chars from the stream, result is a string. | + | Read **n** bytes (in binary mode) or chars (in text mode) from the stream; result is returned as a string. See [[api:non-standard-lua#input_and_output_facilities|io.open]] for more details about how to open files in different modes. |
`local chars = b:read(10)` | `local chars = b:read(10)` | ||
Line 74: | Line 71: | ||
* "\*n" or "\*number" | * "\*n" or "\*number" | ||
- | Read the next series of bytes from the stream and that can be interpreted as a number | + | Read the next series of bytes from the stream that can be interpreted as a number. Note that reading numbers is also affected by the open mode, binary or text. See [[api:non-standard-lua#input_and_output_facilities|io.open]] for more details about how to open files in different modes.. |
`local number = b:read("*n")` | `local number = b:read("*n")` |