Canon Camera Hackers Manual page 197

Camera hackers manual berthold daum
Table of Contents

Advertisement

188
C H A P T E R 5
Scripting
Next is the definition of the table parser_funcs containing two functions.
These functions will be used for parsing the entries of the INI file using
regular expressions. The function with the key "count" checks to see
whether a text line passed in the variable line has the syntax "cnt=..."
where the characters following the equality sign must be decimal digits. At
least one digit is required.
The function with the key "current" checks for text lines with the syntax
"current=...". Here any characters are accepted after the equality sign. In
both cases, the matching characters are captured (and therefore the paren-
theses) and assigned to the local variable s. In the case of success, the value
of s is assigned to the variables ccount resp. config_name and the functions
return true:
parser_funcs={
count = function(line)
local s = line:match(
if s then
ccount = tonumber(s)
return true
end
end,
current = function(line)
local s = line:match(
if s then
config_name = s
return true
end
end,
}
The function copy_file() is used for copying configuration files. In this
case, we first copy to an auxiliary file with the suffix ".NEW" and later re-
name it to the true target file name with the function _activate_file().
Again, we don't want to end up with a corrupted configuration file when
power fails or the memory card is full.
The function first opens the source file in read mode and the target file
in write mode. Because configuration files are not text files but binary files,
we add the "b" option to the mode parameter of the io.open() function.
The content of the source file is then read in chunks of 256 bytes and writ-
ten to the target file. It is essential that we always close files that are suc-
cessfully opened:
"cnt = ([0-9]+)")
"cur=(.+)")

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Powershot sx10 is

Table of Contents