Section 6: Instrument programming
Example: Nil
x = nil
print(x, type(x))
Example: Boolean
y = false
print(y, type(y))
Example: String and number
x = "123"
print(x, type(x))
x = x + 7
print(x, type(x))
Example: Function
function add_two(first_value,
second_value)
return first_value + second_value
end
print(add_two(3, 4), type(add_two))
Example: Table
atable = {1, 2, 3, 4}
print(atable, type(atable))
print(atable[1])
print(atable[4])
Delete a global variable
To delete a global variable, assign nil to the global variable. This removes the global variable from
the runtime environment.
Functions
With Lua, you can group commands and statements using the function keyword. Functions can
take zero, one, or multiple parameters, and they return zero, one, or multiple values.
You can use functions to form expressions that calculate and return a value. Functions can also act
as statements that execute specific tasks.
6-18
Model 2651A High Power System SourceMeter® Instrument Reference Manual
nil
false
123
Adding a number to x forces its type to number.
130
7
Defines a table with four numeric elements.
Note that the table value (shown here as a096cd30)
varies.
table: a096cd30
1
4
boolean
string
number
function
table
2651A-901-01 Rev. C October 2021
Need help?
Do you have a question about the Keithley 2651A and is the answer not in the manual?