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.
Summary of Contents for Camera
Page 1: ......
Page 2: ...The Canon Camera Hackers Manual ...
Page 3: ......
Page 4: ...Berthold Daum The Canon Camera Hackers Manual Teach Your Camera New Tricks ...
Page 19: ...10 CH APTER 2 Cameras and Operating Systems ...
Page 25: ...16 CH APTER 3 ...
Page 85: ...76 CH APTER 4 Teach Your Camera New Tricks ...
Page 213: ...204 CH APTER 6 ...
Page 253: ...244 AP PENDIX ...