Difference between revisions of "Io.lines"

From GiderosMobile
Line 2: Line 2:
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
 
=== Description ===
 
=== Description ===
Opens the given file name in read mode and returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction  
+
<translate>Opens the given file name in read mode and returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction  
  
     `for line in io.lines(filename) do body end`
+
     [[[for line in io.lines(filename) do body end]]]
  
 
  will iterate over all lines of the file. When the iterator function detects the end of file, it returns nil (to finish the loop) and automatically closes the file.  
 
  will iterate over all lines of the file. When the iterator function detects the end of file, it returns nil (to finish the loop) and automatically closes the file.  
  
  
  The call io.lines() (with no file name) is equivalent to io.input():lines(); that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends.
+
  The call io.lines() (with no file name) is equivalent to io.input():lines(); that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends.</translate>
 
<source lang="lua">
 
<source lang="lua">
 
(function) = io.lines(filename)
 
(function) = io.lines(filename)
 
</source>
 
</source>
 
=== Parameters ===
 
=== Parameters ===
'''filename''': (string) filename to open '''optional'''<br/>
+
'''filename''': (string) <translate>filename to open</translate> '''optional'''<br/>
 
=== Return values ===
 
=== Return values ===
'''Returns''' (function) iterator function<br/>
+
'''Returns''' (function) <translate>iterator function</translate><br/>

Revision as of 13:48, 23 August 2018

Available since: Gideros 2011.6

Description

Opens the given file name in read mode and returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction

    [[[for line in io.lines(filename) do body end]]]
will iterate over all lines of the file. When the iterator function detects the end of file, it returns nil (to finish the loop) and automatically closes the file. 


The call io.lines() (with no file name) is equivalent to io.input():lines(); that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends.
(function) = io.lines(filename)

Parameters

filename: (string) filename to open optional

Return values

Returns (function) iterator function