7: Introduction to TSP commands Model DMM7510 7½ Digit Graphical Sampling Multimeter
7-20 DMM7510-901-01 Rev. B / May 2015
Create functions using scripts
You can use scripts to define functions. Scripts that define a function are like any other script: They
do not cause any action to be performed on the instrument until they are executed. The global
variable of the function does not exist until the script that created the function is executed.
A script can consist of one or more functions. Once a script has been run, the computer can call
functions that are in the script directly.
For detail on creating functions, see Fundamentals of scripting for TSP (on page 7-4
).
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
Example: If
print("Zero is true!")
else
print("Zero is false.")
Zero is true!
Example: Comparison
y = 2
if x and y then
print("Both x and y are true")
Both x and y are true