Strings; Tables - Canon Camera Hackers Manual

Camera hackers manual berthold daum
Table of Contents

Advertisement

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])
93
5.4 Lua primer

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Powershot sx10 is

Table of Contents