Keithley 2601B Reference Manual page 292

2600b series system sourcemeter instrument
Hide thumbs Also See for 2601B:
Table of Contents

Advertisement

Series 2600B System SourceMeter® Instrument Reference Manual
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 run-time 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.
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 stored in the run-time environment. Like all data that is
stored in the run-time environment, the function persists until it is removed from the run-time
environment, is overwritten, or the instrument is turned off.
Create functions using the function keyword
Functions are created with a message or in Lua code in either of the following forms:
function myFunction(parameterX) functionBody end
myFunction = function (parameterX) functionBody end
Where:
myFunction: The name of the function.
parameterX: Parameter names. To use multiple parameters, separate the names with commas.
functionBody is the code that is executed when the function is called.
2600BS-901-01 Rev. B / May 2013
Section 6: Instrument programming
7
function
Defines a table with four numeric
elements.
Note that the "table" value (shown here
as a096cd30) will vary.
table: a096cd30
1
4
table
6-15

Advertisement

Table of Contents
loading

This manual is also suitable for:

2604b2614b2634b2635b2636b2602b ... Show all

Table of Contents