92 C H A P T E R 5 Scriptingshould always offer a button to end script execution gracefully. Pressingthe shutter button to interrupt a script should only be done in case ofemergency, because it is not possible to restore the initial state.f The final command in a script is the end command.5.4 Lua primerTo the photographic community, Lua is known as the scripting language forAdobe Lightroom. So, if you have already developed scripts for Lightroom,you have a head start on CHDK scripting. Under the CHDK, Lua featuresmore commands and functions than uBasic, is more platform-independent,and executes about 100 times faster. On the other hand, Lua is an advancedscript language that you cannot master in one afternoon. Here, we willonly introduce the basics of Lua; a description of the complete languagewould be beyond the scope of this book. If you are interested in Lua beyondCHDK scripting, we recommend reading the reference manual [Lua51Ref].5.4.1 VariablesUnlike uBasic, variable names in Lua can be longer than a single character.This allows for an arbitrarily large number of different variables. A variablename must start with a letter or an underscore (_). However, variablenames used as CHDK parameters in the script header (section 5.4.12) mustconsist 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 = 250In contrast to uBasic, variables are not restricted to numeric values; theycan also contain strings, complex structures (tables), and functions (sec-tion 5.4.9). The initial value of a variable is nil (nothing). In the CHDKimplementation 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 platformwhere you execute the script (section 5.8).