io.lines

Returns an iterator function for reading a named file line-by-line

Prototype

it = io.lines (filename)

Description

Opens filename for input in text mode. Raises an error if it cannot.

If opened OK returns an iterator function that reads the file line-by-line.

At end of file, returns nil and closes the file.

If filename not supplied, uses the default input file.

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

 --> Entire contents of file listed

Lua functions

Topics