io
Input and Output Facilities.
file| file:close() | Closes file. |
| file:flush() | Saves any written data to file. |
| file:lines() | Returns an iterator function that, each time it is called, returns a new line from the file. |
| file:read(format) | Reads the file file, according to the given formats, which specify
what to read. |
| file:seek(whence, offset) | Sets and gets the file position, measured from the beginning of the
file, to the position given by offset plus a base specified by the string
whence, as follows:
"set": base is position 0 (beginning of the file);
"cur": base is current position;
"end": base is end of file;
In case of success, function seek returns the final file position,
measured in bytes from the beginning of the file. |
| file:setvbuf(mode, size) | Sets the buffering mode for an output file. |
| file:write(content) | Writes the value of each of its arguments to the file. |
io| io.close(file) | Equivalent to file:close(). |
| io.flush() | Equivalent to file:flush over the default output file. |
| io.input(file) | When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file. |
| io.lines(filename) | Opens the given file name in read mode and returns an iterator function that, each time it is called, returns a new line from the file. |
| io.open(filename, mode) | This function opens a file, in the mode specified in the string mode. |
| io.output(file) | Similar to io.input, but operates over the default output file. |
| io.popen(prog, mode) | Starts program prog in a separated process and returns a file handle
that you can use to read data from this program (if mode is "r",
the default) or to write data to this program (if mode is "w"). |
| io.read(format) | Equivalent to io.input():read. |
| io.stderr | io.stderr Standard error. |
| io.stdin |
|
| io.stdout | io.stdout : Standard out. |
| io.write(content) | Equivalent to io.output():write. |
filefile:close()
file.
file:flush()
file.
file:lines()
io.lines, this function
does not close the file when the loop ends.)
file:read(format)
file, according to the given formats, which specify
what to read.
format
:
file:seek(whence, offset)
offset plus a base specified by the string
whence, as follows:
"set": base is position 0 (beginning of the file);
"cur": base is current position;
"end": base is end of file;
In case of success, function seek returns the final file position,
measured in bytes from the beginning of the file.
whence is "cur", and for offset is 0. Therefore,
the call file:seek() returns the current file position, without changing
it; the call file:seek("set") sets the position to the beginning of the
file (and returns 0); and the call file:seek("end") sets the position
to the end of the file, and returns its size.
whence
:
offset
:
file:setvbuf(mode, size)
There are three available modes:
flush the file (see io.flush)).size specifies the size of the buffer, in
bytes. The default is an appropriate size.
mode
:
size
:
file:write(content)
file.
tostring or
string.format before write.
content
:
ioio.close(file)
file:close().
file, closes the default
output file.
file
:
io.flush()
file:flush over the default output file.
io.input(file)
file
:
io.lines(filename)
io.lines() (with no file name) is equivalent to
io.input():lines(); that is, it iterates over the lines of the default
input file. In this case it does not close the file when the loop ends.
filename
:
io.open(filename, mode)
mode.
mode string can be any of the following:
"r": read mode (the default);
"w": write mode;
"a": append mode;
"r+": update mode, all previous data is preserved;
"w+": update mode, all previous data is erased;
"a+": append update mode, previous data is preserved, writing is only
allowed at the end of file.
The mode string can also have a 'b' at the end, which is needed in
some systems to open the file in binary mode. This string is exactly what
is used in the standard C function fopen.
filename
:
mode
:
#file:
io.output(file)
io.input, but operates over the default output file.
file
:
io.popen(prog, mode)
prog in a separated process and returns a file handle
that you can use to read data from this program (if mode is "r",
the default) or to write data to this program (if mode is "w").
prog
:
mode
:
#file:
io.read(format)
io.input():read.
format
:
io.stderr
io.stdin
io.stdin: Standard in.io.stdout
io.write(content)
io.output():write.
content
: