Keithley SourceMeter 2600 Series Reference Manual page 108

Table of Contents

Advertisement

2-56 TSP Programming Fundamentals
Tables/arrays
TSL makes extensive use of the data type "table," which is essentially a very
flexible array-like data type.
Define a table:
atable = {1, 2, 3, 4}
Let's print it:
i = 1
while atable[i] do
end
Output of code above:
1
2
3
4
Tables can be indexed using element names instead of numeric indicies.
Since functions are 1st class variables, tables can be used to
create "pseudo-classes." Classes are often used in objec-oriented
programming.
Below is a table used to create a circle pseudo-class. It has 3 elements:
clr:
diam:
setdiam: a function, or method, used to change the diameter
circle = {clr = "red", diam = 1, setdiam = function(d)
print(circle["clr"])
print(circle["diam"])
circle["setdiam"](2)
print(circle.diam)
circle.setdiam(3)
print(circle.diam)
2600S-901-01 Rev. A / May 2006
print (atable[i])
i = i + 1
a string containing the color of the circle
a number containing the diameter of the circle
-- Index using a string; print the clr property.
-- Index using a string; print the diam property.
-- Change the diam element by calling setdiam method.
-- circle["diam"] is the same as circle.diam; simpler syntax
-- Change the diameter of the circle again.
-- Print diam property again using simple syntax.
Return to
Series 2600 System SourceMeters Reference Manual
-- A table with four elements, which are numbers.
-- Tables are indexed on one, NOT zero.
atable[index] is true if there is an element at
that index. nil is returned otherwise. 0 does NOT
evaluate to false, only nil does.
-- Index into table using a number.
circle["diam"]=d end}
Section 2 topics

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents