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:
f
The missing CHDK commands can be added as extra libraries to the PC
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/
.
f
When running a script in this environment, the parameters defined in
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.
f
In case of the integer division, you should as a general rule avoid the use
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()
require("chdklib")
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.
Содержание Camera
Страница 1: ......
Страница 2: ...The Canon Camera Hackers Manual ...
Страница 3: ......
Страница 4: ...Berthold Daum The Canon Camera Hackers Manual Teach Your Camera New Tricks ...
Страница 19: ...10 CH APTER 2 Cameras and Operating Systems ...
Страница 25: ...16 CH APTER 3 ...
Страница 85: ...76 CH APTER 4 Teach Your Camera New Tricks ...
Страница 213: ...204 CH APTER 6 ...
Страница 253: ...244 AP PENDIX ...