Adobe 65007312 Programming Guide - Page 12

The Lightroom SDK scripting environment, Namespaces, classes, and objects

Page 12 highlights

CHAPTER 1: Using the Lightroom SDK The Lightroom SDK scripting environment 12 The Lightroom SDK scripting environment The SDK defines a Lua-language scripting API. The Lua scripting language is a fast, light-weight, embeddable scripting language. For information about the language, see http://www.lua.org/. The Lightroom scripting environment provides a programming structure that includes some enhancements to the basic Lua-language constructs. This section describes the API usage and terminology. X The API defined for the Lightroom SDK is fully documented in the Lightroom SDK API Reference, which is part of the SDK. When you have installed the SDK, the home page is at: LR_SDK_install_location/API Reference/index.html Namespaces, classes, and objects Lightroom defines a namespace as a table containing a suite of functions. This is somewhat like the Lua module; however, Lightroom does not use or support the module system that was introduced in Lua 5.1 (see http://www.lua.org/manual/5.1/manual.html#5.3). Lua does not have an object-oriented programming model, but it does allow Lua tables to be used in an object-like fashion, which the Lightroom SDK does. Lightroom's object and class model is derived from the one described in Chapter 16 of "Programming in Lua," available online at http://www.lua.org/pil/16.html. In Lightroom terminology, object and class are used in the typical object-oriented fashion: that is, a class is a description of a set of behaviors that are associated with a particular data structure, and an object is a single instance of that class. X The Lightroom SDK defines a set of namespaces and a set of classes; see "Accessing namespace functions directly" on page 12 and "Creating objects" on page 14. Plug-ins cannot define either namespaces or classes. X The Lua language defines built-in namespaces and global functions, of which a subset are accessible in the Lightroom SDK Lua environment. See "Using built-in Lua features" on page 19. Accessing namespace functions directly You can access a namespace by using the built-in function import(); it takes a single parameter, the name of the namespace to be loaded, and returns the table of functions, which you can then access using dot notation. For example: local LrMD5 = import 'LrMD5' -- assign namespace to local variable local digest = LrMD5.digest( 'some string' ) -- call "digest()" function in namespace This example shows the convention of assigning the namespace to a variable of the same name. This practice is not enforced in any way, but helps avoid confusion.

  • 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
12
The Lightroom SDK scripting environment
The SDK defines a Lua-language scripting API. The Lua scripting language is a fast, light-weight,
embeddable scripting language. For information about the language, see
.
The Lightroom scripting environment provides a programming structure that includes some
enhancements to the basic Lua-language constructs. This section describes the API usage and
terminology.
X
The API defined for the Lightroom SDK is fully documented in the
Lightroom SDK API Reference
, which
is part of the SDK. When you have installed the SDK, the home page is at:
LR_SDK_install_location
/API Reference/index.html
Namespaces, classes, and objects
Lightroom defines a
namespace
as a table containing a suite of functions. This is somewhat like the Lua
module
; however, Lightroom does not use or support the module system that was introduced in Lua 5.1
(see
).
Lua does not have an object-oriented programming model, but it does allow Lua tables to be used in an
object-like fashion, which the Lightroom SDK does. Lightroom’s object and class model is derived from the
one described in Chapter 16 of "Programming in Lua," available online at
.
In Lightroom terminology,
object
and
class
are used in the typical object-oriented fashion: that is, a class is
a description of a set of behaviors that are associated with a particular data structure, and an object is a
single instance of that class.
X
The Lightroom SDK defines a set of namespaces and a set of classes; see
“Accessing namespace
functions directly” on page 12
and
“Creating objects” on page 14
. Plug-ins cannot define either
namespaces or classes.
X
The Lua language defines built-in namespaces and global functions, of which a subset are accessible
in the Lightroom SDK Lua environment. See
“Using built-in Lua features” on page 19
.
Accessing namespace functions directly
You can access a namespace by using the built-in function
import()
; it takes a single parameter, the name
of the namespace to be loaded, and returns the table of functions, which you can then access using dot
notation.
For example:
local LrMD5 = import 'LrMD5' -- assign namespace to local variable
local digest = LrMD5.digest( 'some string' ) -- call "digest()" function in namespace
This example shows the convention of assigning the namespace to a variable of the same name. This
practice is not enforced in any way, but helps avoid confusion.