5.4 Lua primer
93
5.4.2 Strings
Strings are enclosed in single (
‘...’
) or double (
“...”
) quotes, or in dou-
bled square brackets (
[[...]]
). With this latter form, it is possible to define
strings that stretch across multiple lines. Strings can contain most of the
escape sequences used in other programming languages such as C or Java:
\f
for a form feed,
\n
for a new line,
\r
for the carriage return. Strings can
be concatenated with the
..
operator:
"CH"..
'
DK'
5.4.3
Tables
Tables are a core concept in
Lua
. Tables can contain an arbitrary number of
elements—numbers, strings, functions, and other tables.
Table definitions are enclosed in curly brackets (
{}
). Anything (except
nil
) can be a table element. Table elements can be addressed through the
element index. For instance:
disp_table = {'info',
'
no_info
'
,
'
off
'
,
'
electronic_viewfinder
'
}
print(disp_table[2])
would print ‘no_info’ because indexing starts at 1. The number of table ele-
ments can be obtained through the operator
#
:
print(#disp_table)
would print ‘4’.
Alternatively, table elements can be associated with explicit keys, in
which case the table works as a dictionary:
reverse_disp_table = {info = 0,
no_info = 1, off = 2,
electronic_viewfinder = 3}
In this case we could address the elements by their key:
print(reverse_disp_table["info"])
would print ‘0’. The following dot notation is also possible:
print(reverse_disp_table.info])
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 ...