Canon Camera Hackers Manual page 106

Camera hackers manual berthold daum
Table of Contents

Advertisement

for i = 1,10,3 do
print(i)
end
would print the values 1, 4, 7, 10.
A second form of the for statement—called the generic for state-
ment—allows iteration over a series of values, such as the elements of a
table. Using the built-in function ipairs(), we can write:
disp_table = {'info', 'no_info', 'off', 'electronic_viewfinder'}
for i,v in ipairs(disp_table) do
print(i,v)
end
This results in the output:
1
info
2
no_info
3
off
4
electronic_viewfinder
The same is possible for dictionary tables that are accessible via keywords.
Instead of ipairs(), the function pairs() is used in this case:
t = {info = 0, no_info = 1, off = 2, electronic_viewfinder = 3}
for key,value in pairs(t) do
print(key,value)
end
The result of this script would be:
electronic_viewfinder
off
info
no_info
Note that in this case the order in which the values are obtained cannot be
predicted.
In addition to the various flavors of the for statement, Lua also features
a while statement and a repeat statement. The latter replaces the do...
until construct found in uBasic.
3
2
0
1
97
5.4 Lua primer

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Powershot sx10 is

Table of Contents