6.8 – Input and Output Facilities

The I/O library provides two different styles for file manipulation. The first one uses implicit file handles; 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 handles.

When using implicit file handles, all operations are supplied by table io. When using explicit file handles, the operation io.open returns a file handle and then all operations are supplied as methods of the file handle.

The table io also provides three predefined file handles with their usual meanings from C: io.stdin, io.stdout, and io.stderr. The I/O library never closes these files.

Unless otherwise stated, all I/O functions return nil on failure (plus an error message as a second result and a system-dependent error code as a third result) and some value different from nil on success. On non-POSIX systems, the computation of the error message and error code in case of errors may be not thread safe, because they rely on the global C variable errno.

file:flush()

file:flush () Saves any written data to file.

2017-02-21 04:11:01
io.close()

io.close ([file]) Equivalent to file:close(). Without a file, closes the default output file.

2017-02-21 04:11:28
file:write()

file:write (···) Writes the value of each of its arguments to file. The arguments must be strings or numbers. In case of success, this function returns file

2017-02-21 04:11:05
io.tmpfile()

io.tmpfile () In case of success, returns a handle for a temporary file. This file is opened in update mode and it is automatically removed when the program ends.

2017-02-21 04:11:33
file:close()

file:close () Closes file. Note that files are automatically closed when their handles are garbage collected, but that takes an unpredictable amount of time to happen

2017-02-21 04:11:00
file:setvbuf()

file:setvbuf (mode [, size]) Sets the buffering mode for an output file. There are three available modes: "no": no buffering; the result of

2017-02-21 04:11:04
io.lines()

io.lines ([filename, ···]) Opens the given file name in read mode and returns an iterator function that works like file:lines(···) over the opened file. When the

2017-02-21 04:11:30
io.open()

io.open (filename [, mode]) This function opens a file, in the mode specified in the string mode. In case of success, it returns a new file handle. The mode

2017-02-21 04:11:30