Model 2651A High Power System SourceMeter® Instrument Reference Manual
Section 6: Instrument programming
2651A-901-01 Rev. A / March 2011
6-23
Operator precedence
Precedence
Operator
Highest
^
(exponentiation)
.
not, -
(unary)
.
*, /
.
+, -
.
..
(concatenation)
.
<, >, <=, >=, ~=, ==
.
and
Lowest
or
You can use parentheses to change the precedences in an expression. The concatenation ("
..
") and
exponentiation ("
^
") operators are right associative. All other binary operators are left associative. The
examples below show equivalent expressions.
Equivalent expressions
r offset < testValue/2+0.5
=
(r offset) <
((testValue/2)+0.5)
3+reading^2*4
=
3+((reading^2)*4)
Rdg < maxRdg and lastRdg <=
expectedRdg
=
(Rdg < maxRdg) and (lastRdg
<=expectedRdg)
-reading^2
=
-(reading^2)
reading^testAdjustment^2
=
reading^(testAdjustment^2)
Conditional branching
Lua uses the
if
,
else
,
elseif
,
then
, and
end
keywords to do conditional branching.
Note that in Lua,
nil
and
false
are
false
and everything else is
true
. Zero is
true
in Lua.
The syntax of a conditional block is as follows:
if
expression
then
block
elseif
expression
then
block
else
block
end
Where:
•
expression
is Lua code that evaluates to either
true
or
false
•
block
consists of one or more Lua statements