Difference between revisions of "X file:read"
From GiderosMobile
m |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 5: | Line 5: | ||
=== Description === | === Description === | ||
Reads a file according to given formats which specify what to read. | Reads a file according to given formats which specify what to read. | ||
− | < | + | <syntaxhighlight lang="lua"> |
(string) = file:read(format1,...) | (string) = file:read(format1,...) | ||
</source> | </source> |
Latest revision as of 14:32, 13 July 2023
Available since: Gideros 2011.6
Class: file
Description
Reads a file according to given formats which specify what to read. <syntaxhighlight lang="lua"> (string) = file:read(format1,...) </source>
For each format, the function returns a string (or a number) with the characters read, or nil if it cannot read data with the specified format.
When called without formats, it uses a default format that reads the entire next line (see below).
The available formats are:
- "*n": reads a number; this is the only format that returns a number instead of a string
- "*a": reads the whole file, starting at the current position. On end of file, it returns the empty string
- "*l": reads the next line (skipping the end of line), returning nil on end of file. This is the default format.
- number: reads a string with up to this number of characters, returning nil on end of file. If number is zero, it reads nothing and returns an empty string, or nil on end of file.
Parameters
format1: (string) format
...: (string) more optional formats optional
Return values
Returns (string) read string from file