Adobe 65007312 Programming Guide - Page 21

Lua syntax notes, It is useful to read the on table constructors

Page 21 highlights

CHAPTER 1: Using the Lightroom SDK The Lightroom SDK scripting environment 21 SomeFile.doSomething( 42 ) Lua syntax notes For people unfamiliar with the Lua language, here are some syntax conventions and usage notes. X Literal strings can be surrounded by either single or double quotes. These two statements are equivalent: local a = 'my string' local a = "my string" X Semicolons at the ends of statements are optional. We typically omit them. X If you call a function with a single parameter that is a string literal or a table, you can omit the parentheses around the argument list. This is frequently done when calling the built-in functions import() and require(). These three statements are equivalent (where func is a variable containing a valid function): func( "foo" ) func "foo" func 'foo' These two statements are also equivalent; the simpler syntax is commonly used when building view descriptions: func( { a = 1, b = 2 } ) func{ a = 1, b = 2 } X It is useful to read the chapter on table constructors (http://www.lua.org/pil/3.6.html). There are several shorthand formats that we use widely, especially in view descriptions. For example, these forms are equivalent: local t = { a = 1, b = 2 } local t = { [ "a" ] = 1, [ "b" ] = 2 } local t = {}; t.a = 1; t.b = 2 X Lua defines an array as a table with numbered keys. Arrays in Lua are 1-based; that is, the first item in the array is at index 1, not index 0. X The value nil evaluates to a Boolean value of false, but numbers (including 0) evaluate to true. Thus, in a conditional, only nil and false are considered false. If you use 0 as the condition of an if or while statement for example, the statement is executed, because the number 0 is a true value. X Lightroom defines Boolean globals, WIN_ENV and MAC_ENV, which you can use to determine which platform your script is running on. The LrSystemInfo namespace (first available in version 3.0 of the Lightroom SDK) can provide additional information about the platform, including whether is 32-bit or 64-bit.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204

C
HAPTER
1: Using the Lightroom SDK
The Lightroom SDK scripting environment
21
SomeFile.doSomething( 42 )
Lua syntax notes
For people unfamiliar with the Lua language, here are some syntax conventions and usage notes.
X
Literal strings can be surrounded by either single or double quotes. These two statements are
equivalent:
local a = 'my string'
local a = "my string"
X
Semicolons at the ends of statements are optional. We typically omit them.
X
If you call a function with a single parameter that is a string literal or a table, you can omit the
parentheses around the argument list. This is frequently done when calling the built-in functions
import()
and
require()
.
These three statements are equivalent (where
func
is a variable containing a valid function):
func( "foo" )
func "foo"
func 'foo'
These two statements are also equivalent; the simpler syntax is commonly used when building view
descriptions:
func( { a = 1, b = 2 } )
func{ a = 1, b = 2 }
X
It is useful to read the chapter on table constructors (
). There are
several shorthand formats that we use widely, especially in view descriptions. For example, these
forms are equivalent:
local t = { a = 1, b = 2 }
local t = { [ "a" ] = 1, [ "b" ] = 2 }
local t = {}; t.a = 1; t.b = 2
X
Lua defines an
array
as a table with numbered keys. Arrays in Lua are 1-based; that is, the first item in
the array is at index 1, not index 0.
X
The value
nil
evaluates to a Boolean value of false, but numbers (including 0) evaluate to true. Thus,
in a conditional, only
nil
and
false
are considered false. If you use 0 as the condition of an
if
or
while
statement for example, the statement
is
executed, because the number 0 is a true value.
X
Lightroom defines Boolean globals,
WIN_ENV
and
MAC_ENV
, which you can use to determine which
platform your script is running on. The
LrSystemInfo
namespace (first available in version 3.0 of the
Lightroom SDK) can provide additional information about the platform, including whether is 32-bit or
64-bit.