Difference between revisions of "X file:lines"
From GiderosMobile
(Created page with "__NOTOC__ <languages /> '''<translate>Available since</translate>:''' Gideros 2011.6<br/> '''<translate>Class</translate>:''' file<br/> === <transl...") |
|||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
| − | + | '''Available since:''' Gideros 2011.6<br/> | |
| − | ''' | + | '''Class:''' [[file|file]]<br/> |
| − | ''' | ||
| − | |||
| − | |||
| − | + | === 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/> | ||
| − | + | === Example === | |
| − | < | + | '''To iterate over all lines of a file''' |
| − | + | <syntaxhighlight lang="lua"> | |
| − | + | for line in file:lines() do | |
| − | + | --body | |
| − | + | end | |
| + | </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