Section 6: Instrument programming
Model 2651A High Power System SourceMeter® Instrument Reference Manual
6-22
2651A-901-01 Rev. A / March 2011
Logical operators
The logical operators in Lua are
and
,
or
, and
not
. All logical operators consider both
false
and
nil
as false and anything else as true.
The operator
not
always returns
false
or
true
.
The conjunction operator
and
returns its first argument if this value is
false
or
nil
; otherwise,
and
returns its second argument. The disjunction operator
or
returns its first argument if this value is
different from
nil
and
false
; otherwise,
or
returns its second argument. Both the
and
and the
or
logical operators use shortcut evaluation, that is, the second operand is evaluated only if necessary.
Example
print(10 or errorqueue.next())
print(nil or "a")
print(nil and 10)
print(false and errorqueue.next())
print(false and nil)
print(false or nil)
print(10 and 20)
1.01
a
nil
false
false
nil
2.01
String concatenation
String operators
Operator Description
..
Concatenates two strings. If both operands are strings or number, they are converted
to strings according to Lua coercion rules, as follows:
•
Any arithmetic operation applied to a string tries to convert that string to a number,
following the usual rules.
•
Whenever a number is used where a string is expected, the number is converted to a
string, in a reasonable format.
Example: Concatenation
print(2 .. 3)
print("Hello " .. "World")
23
Hello World
Operator precedence
Operator precedence in Lua follows the order below (from higher to lower priority).