Canon Camera Hackers Manual page 113

Camera hackers manual berthold daum
Table of Contents

Advertisement

104
C H A P T E R 5
Scripting
value1,... = file:read(format1,...)
For each of the specified formats, read() will return a numeric or string
value read from the input file. If the specified format cannot be satisfied,
nil is returned instead. The following formats are available:
"*n"
Reads a number.
"*a"
Reads the whole file, starting at the current position. If the current posi-
tion is at the end of the file, nil is returned.
"*l"
Reads the next line. nil is returned at the end of the file.
number
Reads a string with up to the specified number of characters. nil is
returned at the end of the file.
pos, msg = file:seek(mode, offset)
positions the write and read pointers to the specified offset in the file, be-
ginning at the origin specified in mode. offset can be omitted and defaults
to 0 in that case. In case of an error, pos is nil, and an error message is given
in msg.
"set"
Starts at the beginning of the file.
"cur"
Starts at the current position. This is the default when the mode
parameter is omitted.
"end"
Starts at the end of the file and subtracts the offset.
Example:
function fsize(file)
local current_pos = file:seek()
local size = file:seek("end")
file:seek("set", current_pos)
return size
end
This function determines the size of a file. It first saves the current position
into the local variable current_pos, and then positions to the file end and
stores that position in the variable size. As a good citizen, it restores the
original position and then returns size as result.

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Powershot sx10 is

Table of Contents