Canon Camera Hackers Manual page 112

Camera hackers manual berthold daum
Table of Contents

Advertisement

IO functions
The Lua IO library provides access to file input and output. Using these
functions, it is possible to read and write files located on the memory card.
We will only give a short overview of the most important IO functions. Ex-
amples for the application of these functions are found in section 5.7.1.
file, msg, no = io.open(filename, mode)
opens a file with the specified name and in the specified mode. A "b"
appended to the mode strings indicates a binary file:
"r"
Read mode (the default if the mode parameter is omitted).
"w"
Write mode. A new file is created, and existing files are overwritten.
"a"
Append mode. Appends to the end of an existing file.
In case of an error, the return variable file is nil and an error message is
given in msg, an error code in no.
ret, msg, no = io.close(file)
ret, msg, no = file:close()
Closes the specified file. In case of an error, ret is nil, and an error message
is given in msg, an error code in no.
ret, msg, no = io.flush()
Performs all outstanding buffered write operations and makes sure that all
written data is physically stored.
ret, msg, no = file:lines()
Creates an iterator over the lines in a text file. It can be used in the follow-
ing way:
for line in file:lines()
do ... end
Here, the variable line will subsequently contain each line in the specified
file. If no more lines are available, nil will be returned.
103
5.4 Lua primer

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Powershot sx10 is

Table of Contents