Keithley 2651A Reference Manual page 262

High power system sourcemeter instrument
Hide thumbs Also See for 2651A:
Table of Contents

Advertisement

Section 6: Instrument programming
Example: String and number
x = "123"
print(x, type(x))
x = x + 7
print(x, type(x))
Example: Function
function add_two(parameter1,
parameter2)
return parameter1 + parameter2
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])
To delete a global variable, assign nil to the global variable. This removes the global variable from
the runtime environment.
Functions
Lua makes it simple to group commands and statements using the function keyword. Functions
can take zero, one, or multiple parameters, and they return zero, one, or multiple parameters.
Functions can be used to form expressions that calculate and return a value; they also can act as
statements that execute specific tasks.
Functions are first-class values in Lua. That means that functions can be stored in variables, passed
as arguments to other functions, and returned as results. They can also be stored in tables.
Note that when a function is defined, it is a global variable in the runtime environment. Like all global
variables, the functions persist until they are removed from the runtime environment, are overwritten,
or the instrument is turned off.
Create functions using the function keyword
Functions are created with a message or Lua code in the form:
myFunction = function (parameterX) functionBody end
6-18
Model 2651A High Power System SourceMeter® Instrument Reference Manual
123
Adding a number to x forces its type to
number
1.30000e+02
7.00000e+00
Defines a table with four numeric
elements.
Note that the "table" value (shown here
as a096cd30) will vary.
table: a096cd30
1.00000e+00
4.00000e+00
string
number
function
table
2651A-901-01 Rev. A / March 2011

Advertisement

Table of Contents
loading

Table of Contents