f:read

Reads the file according to the specified formats

Prototype

v1, v2 ... = f:read (format1, format2, ...)

Description

Reads the file f according to the given formats. Each format returns a string, a number, or nil and an error code if it fails (see below). The formats are:

f = io.input ("test.txt")
repeat
  s = f:read ("*l") -- read one line
  if s then  -- if not end of file (EOF)
   print (s) -- print that line
  end
until not s  -- until end of file

f:close ()  -- close that file now
If the file cannot be read the function returns 3 things:

Lua functions

Topics