92
C H A P T E R 5
Scripting
should always offer a button to end script execution gracefully. Pressing
the shutter button to interrupt a script should only be done in case of
emergency, because it is not possible to restore the initial state.
f
The final command in a script is the
end
command.
5.4
Lua primer
To the photographic community,
Lua
is known as the scripting language for
Adobe Lightroom
. So, if you have already developed scripts for
Lightroom,
you have a head start on CHDK scripting. Under the CHDK,
Lua
features
more commands and functions than
uBasic,
is more platform-independent,
and executes about 100 times faster. On the other hand,
Lua
is an advanced
script language that you cannot master in one afternoon. Here, we will
only introduce the basics of
Lua;
a description of the complete language
would be beyond the scope of this book. If you are interested in
Lua
beyond
CHDK scripting, we recommend reading the reference manual [Lua51Ref].
5.4.1 Variables
Unlike
uBasic,
variable names in
Lua
can be longer than a single character.
This allows for an arbitrarily large number of different variables. A variable
name must start with a letter or an underscore (
_
). However, variable
names used as CHDK parameters in the script header (section 5.4.12) must
consist of a single lower-case letter and can only accept numeric values.
There is also an anonymous variable—typically used as a placeholder—
with only the underscore (
_
) as its name.
Variables can be defined as global or local. Local variables are only avail-
able in the local context of the defining block (section 5.4.6) or function
(section 5.4.9). Their definition starts with the keyword
local
, e.g.,
local speed = 250
In contrast to
uBasic,
variables are not restricted to numeric values; they
can also contain strings, complex structures (tables), and functions (sec-
tion 5.4.9). The initial value of a variable is
nil
(nothing). In the CHDK
implementation of
Lua,
numeric values are restricted to integer values—
floating-point arithmetic is
not
supported. This has implications for porta-
bility; the result of computations may differ depending on the platform
where you execute the script (section 5.8).
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 ...