The I/O library provides two different styles for file manipulation. The first one uses implicit file descriptors; that is, there are operations to set a default input file and a default output file, and all input/output operations are over these default files. The second style uses explicit file descriptors.

When using implicit file descriptors, all operations are supplied by table io When using explicit file descriptors, the operation io.open (filename [, mode]) returns a file descriptor and then all operations are supplied as methods of the file descriptor.

The table io also provides three predefined file descriptors with their usual meanings from C: io.stdin io.stdout and io.stderr

Unless otherwise stated, all I/O functions return nil on failure (plus an error message as a second result) and some value different from nil on success.


Subsections

  1. io.close ([file])
  2. io.flush ()
  3. io.input ([file])
  4. io.lines ([filename])
  5. io.open (filename [, mode])
  6. io.output ([file])
  7. io.popen (prog [, mode])
  8. io.read (...)
  9. io.tmpfile ()
  10. io.type (obj)
  11. io.write (...)
  12. file:close ()
  13. file:flush ()
  14. file:lines ()
  15. file:read (...)
  16. file:seek ([whence] [, offset])
  17. file:setvbuf (mode [, size])
  18. file:write (...)