Section 8: Instrument programming Series 2600B System SourceMeter® instrument Reference Manual
8-22 2600BS-901-01 Rev. F/August 2021
Operator precedence
Operator precedence in Lua follows the order below (from higher to lower priority):
• ^ (exponentiation)
• not, - (unary)
• *, /
• +, –
• .. (concatenation)
• <, >, <=, >=, ~=, ==
• and
• 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.
reading + offset < testValue/2+0.5
(reading + offset) < ((testValue/2)+0.5)
Rdg < maxRdg and lastRdg <=
expectedRdg
(Rdg < maxRdg) and (lastRdg <= expectedRdg)
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 (0) 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