Canon Camera Hackers Manual page 205

Camera hackers manual berthold daum
Table of Contents

Advertisement

196
C H A P T E R 5
Scripting
However, all of these problems can be solved so that Lua scripts can be
tested comfortably within a PC environment:
The missing CHDK commands can be added as extra libraries to the PC
f
environment. These libraries will only be included in the script when it
runs on a PC. On the book CD, you will find these libraries in the folder
luaDebug/ under the names chdklib.lua, os_ext.lua, and bit.lua.
Simply place these libraries into the same (PC) folder as your script. By
default, library chdklib.lua is configured for DryOS, but it can easily be
reconfigured for VxWorks (set variable propset to 1).
f
In addition, you must include the contents of the folder CHDK/LUALIB/
in your script folder. At the time of writing, these are the libraries
propcase.lua and capmode.lua, and the subfolder is GEN/.
When running a script in this environment, the parameters defined in
f
the script header are parsed by the library chdklib.lua and assigned to
Lua variables so that the script will run with the same configuration as
under the CHDK.
In case of the integer division, you should as a general rule avoid the use
f
of the division operator (/) and instead use the function idiv(), which
is defined as:
function idiv(a,b)
return (a-(a%b))/b
end
This function implements an integer division and delivers the same
results on the PC and the CHDK.
All that remains to be done is to add the definition of idiv() and the fol-
lowing statement block to your script:
pcall(function()
end
)
When the library chdklib.lua is not available (as when running under the
CHDK), this expression does nothing at all. The error condition raised by the
require() command is caught by the pcall() function.
By using this technique, you can conveniently test a CHDK Lua script on
a PC.
require("chdklib")

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Powershot sx10 is

Table of Contents