X file:lines: Difference between revisions

From GiderosMobile
Created page with "__NOTOC__ <languages /> '''<translate>Available since</translate>:''' Gideros 2011.6<br/> '''<translate>Class</translate>:''' file<br/> === <transl..."
 
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
<languages />
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
'''Class:''' [[X File]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/file|file]]<br/>
=== <translate>Description</translate> ===
<translate>Returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction


    ''for line in file:lines() do body end''
=== Description ===
Returns an iterator function that, each time it is called, returns a new line from the file.
<syntaxhighlight lang="lua">
(function) = file:lines()
</syntaxhighlight>
 
Unlike '''[[io.lines]]''', this function does not close the file when the loop ends.
 
=== Return values ===
'''Returns''' (function) iterator function<br/>


will iterate over all lines of the file. (Unlike io.lines, this function does not close the file when the loop ends.)</translate>
=== Example ===
<source lang="lua">
'''To iterate over all lines of a file'''
(function) = file:lines()
<syntaxhighlight lang="lua">
</source>
for line in file:lines() do
=== <translate>Return values</translate> ===
--body
'''<translate>Returns</translate>''' (function) <translate>iterator function</translate><br/>
end
</syntaxhighlight>


{{File}}
{{X File}}

Latest revision as of 21:39, 24 January 2026

Available since: Gideros 2011.6
Class: X File

Description

Returns an iterator function that, each time it is called, returns a new line from the file.

(function) = file:lines()

Unlike io.lines, this function does not close the file when the loop ends.

Return values

Returns (function) iterator function

Example

To iterate over all lines of a file

for line in file:lines() do
	--body
end