102
C H A P T E R 5
Scripting
Some standard libraries are already included in
Lua,
such as:
f
Basic library for some
core functions
f
Input and output
library
f
Operating system
facilities library
f
String manipulation
library
f
Mathematical functions
library. The CHDK version of this library differs
substantially from the standard version because all functions dealing
with floating point numbers have been removed (section 5.4.1).
Other libraries can easily be added to
Lua
by placing them into the folder
/CHDK/LUALIB
. Before such a library can be accessed in a script, it must be
loaded. This is done with the statement:
require("library_name")
where the library name is written without the suffix “.lua”. It is possible to
assign the result of function
require()
to a variable. Often libraries con-
struct a table containing all public functions and values defined in the
library, and return this table to the loader. The loader may then retrieve
these functions and values. For example:
props = require("propcase")
id = props.DISPLAY_MODE
Here the library
propcase.lua
has returned the table
props
containing a
value under key
DISPLAY_MODE
. This technique helps avoid name clashes
when several libraries are used at the same time.
The following libraries are automatically loaded:
Lua core functions
The core library implements functions such as the already discussed
pcall()
,
error(),
or
print()
. The following functions can also be useful:
dofile(fname)
Loads the specified file as a new
Lua
script and executes it.
tonumber(p,b)
Converts
p
to a number to the specified base
b
. If
b
is
omitted, a base of 10 (the decimal system) is assumed.
tostring(p)
Converts the parameter
p
into a string.
type(p)
Returns the type of
p
. Possible return values are: “nil”,
“number”, “string”, “boolean, “table”, “function”, “thread”,
and “userdata”.
Содержание 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 ...