Skip to main content

lines

Function lines 

Source
pub fn lines(filename: option<string>, formats: Repeatable<string>) -> function
Expand description

Iterates over the lines of a named file.

§Parameters

  • filename: the file to open in read mode. When absent, iterates over the default input file.
  • ···: read formats, as in file::read (default "l").

§Return value

An iterator function. Unlike file::lines, this form closes the file automatically when the loop ends, when it fails, or when it is interrupted by a break inside a generic for.

§Examples

for line in io.lines("notes.txt") do
  print(line)
end

§See also

file::lines, open