Difference between revisions of "X file:lines"

From GiderosMobile
(redone)
 
(One intermediate revision by one other user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Returns an iterator function that, each time it is called, returns a new line from the file.
 
Returns an iterator function that, each time it is called, returns a new line from the file.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(function) = file:lines()
 
(function) = file:lines()
</source>
+
</syntaxhighlight>
  
 
Unlike '''[[io.lines]]''', this function does not close the file when the loop ends.
 
Unlike '''[[io.lines]]''', this function does not close the file when the loop ends.
Line 16: Line 16:
 
=== Example ===
 
=== Example ===
 
'''To iterate over all lines of a file'''
 
'''To iterate over all lines of a file'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
for line in file:lines() do
 
for line in file:lines() do
 
--body
 
--body
 
end
 
end
</source>
+
</syntaxhighlight>
  
 
{{File}}
 
{{File}}

Latest revision as of 04:10, 30 July 2025

Available since: Gideros 2011.6
Class: 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