Adobe 65007312 Programming Guide - Page 21
Lua syntax notes, It is useful to read the on table constructors
UPC - 883919154398
View all Adobe 65007312 manuals
Add to My Manuals
Save this manual to your list of manuals |
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.