Difference between revisions of "X file:read"

From GiderosMobile
(Created page with "__NOTOC__ <languages /> '''<translate>Available since</translate>:''' Gideros 2011.6<br/> '''<translate>Class</translate>:''' file<br/> === <transl...")
 
(redone)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[file|file]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/file|file]]<br/>
 
=== <translate>Description</translate> ===
 
<translate>Reads the file file, according to the given formats, which specify what to read. 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).
 
  
 +
=== Description ===
 +
Reads a file according to a given formats which specify what to read.
 +
<source lang="lua">
 +
(string) = file:read(format1,...)
 +
</source>
  
The available formats are
+
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).
  
"*n": reads a number; this is the only format that returns a number instead of a string.  
+
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.
  
"*a": reads the whole file, starting at the current position. On end of file, it returns the empty string.
+
=== Parameters ===
 +
'''format1''': (string) format<br/>
 +
'''...''': (string) more optional formats '''optional'''<br/>
  
"*l": reads the next line (skipping the end of line), returning nil on end of file. This is the default format.
+
=== Return values ===
 
+
'''Returns''' (string) read string from file<br/>
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.</translate>
 
<source lang="lua">
 
(string) = file:read(format1,...)
 
</source>
 
=== <translate>Parameters</translate> ===
 
'''format1''': (string) <translate>format</translate> <br/>
 
'''...''': (string) <translate>more optional formats</translate> '''optional'''<br/>
 
=== <translate>Return values</translate> ===
 
'''<translate>Returns</translate>''' (string) <translate>read string from file</translate><br/>
 
  
 
{{File}}
 
{{File}}

Revision as of 06:29, 7 December 2020

Available since: Gideros 2011.6
Class: file

Description

Reads a file according to a given formats which specify what to read.

(string) = file:read(format1,...)

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