User manual
Series 3700 System Switch/Multimeter Reference Manual Section 2: TSP Programming Fundamentals
3700S-901-01 Rev. C / July 2008 2-37
Tables can be indexed using element names instead of numeric indices.
Because functions are first-class variables, tables can be used to create
"pseudoclasses." Classes are often used in object-oriented programming.
Below is a table used to create a circle pseudoclass. It has 3 elements:
clr
A string containing the color of the circle
diam
A number containing the diameter of the circle
setdiam
A function, or method, used to change the diameter
circle = {clr = 'red', diam = 1, setdiam = function(d)
circle['diam']=d end}
-- Index using a string; print the clr property.
print(circle['clr'])
-- Index using a string; print the diam property.
print(circle['diam'])
-- Change the diam element by calling setdiam.
circle['setdiam'](2)
-- Print the diameter of the circle; circle['diam'] is a
simpler syntax of circle.diam
print(circle.diam)
-- Change the diameter of the circle again.
circle.setdiam(3)
-- Print diam property again using simple syntax.
print(circle.diam)
Output of code above:
red
1
2
3
Precedence
Operator precedence in TSL follows the table below, from higher to lower
priority:
^
not
- (unary)
*
/
+
-
.. (concatenation)
< <= >= ~= ==
and