![background image](http://html1.mh-extra.com/html/keithley/2651a/2651a_reference-manual_661729262.webp)
Section 6: Instrument programming
Model 2651A High Power System SourceMeter® Instrument Reference Manual
6-18
2651A-901-01 Rev. A / March 2011
Example: String and number
x = "123"
print(x, type(x))
x = x + 7
print(x, type(x))
123 string
Adding a number to x forces its type to
number
1.02 number
Example: Function
function add_two(parameter1,
parameter2)
return para parameter2
end
print(add_two(3, 4), type(add_two))
7.00 function
Example: Table
atable = {1, 2, 3, 4}
print(atable, type(atable))
print(atable[1])
print(atable[4])
Defines a table with four numeric
elements.
Note that the "table" value (shown here
as
a096cd30
) will vary.
table: a096cd30 table
1.00
4.00
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