2600AS-901-01 Rev. B / September 2008
Return to
19-237
Series 2600A System SourceMeter® Instruments Reference Manual
Section 19: Remote Commands
String library functions
This library provides generic functions for string manipulation, such as finding and extracting
substrings. When indexing a string in TSL, the first character is at position 1 (not 0 as in ANSI C).
Indices may be negative and are interpreted as indexing backwards, from the end of the string.
Thus, the last character is at position 1, and so on.
Math library functions
This library is an interface to most of the functions of the ANSI C math library. All trigonometric
functions work in radians. The functions
math.deg()
and
math.rad()
convert between radians
and degrees.
tostring(x)
Receives an argument of any type and converts it to a string in a
reasonable format.
type(v)
Returns the type of its only argument, coded as a string. The
possible results of this function are: nil, number, Boolean, table,
or function.
NOTE
: TSL does automatic memory management. That means that you do not have to worry about
allocating memory for new objects and freeing it when the objects are no longer needed. TSL manages
memory automatically by running a garbage collector from time to time to collect all dead objects (that is,
those objects that are no longer accessible from TSL). All objects in TSL are subject to automatic
management: tables, variables, functions, threads, and strings. TSL uses two numbers to control its
garbage-collection cycles. One number counts how many bytes of dynamic memory TSL is using; the
other is a threshold. When the number of bytes crosses the threshold, TSL runs the garbage collector,
which reclaims the memory of all dead objects. The byte counter is adjusted, and then the threshold is
reset to twice the new value of the byte counter.
string.byte(s [,i])
Returns the internal numerical code of the i-th character of string s, or nil if
the index is out of range.
string.char(i1, i1, …)
Receives 0 or more integers. Returns a string with length equal to the
number of arguments, in which each character has the internal numerical
code equal to its corresponding argument.
string.format(fs, e1, e2, …)
Returns a formatted version of its variable number of arguments following
the description given in its first argument, which must be a string. The format
string follows the same rules as the print family of ANSI C functions. The
only differences are that the options/modifiers *, l, L, n, p, and h are not
supported. The options c, d, E, e, f, g, G, I, o, u, X, and x all expect a numeric
argument, where s expects a string argument. String values to be formatted
with %s cannot contain embedded zeros.
string.len(s)
Returns the length of the strings.
string.lower(s)
Returns a copy of the string s with all uppercase letters changed to
lowercase.
string.rep(s, n)
Returns a string that is the concatenation of n copies of the string s.
string.sub(s, i [,j])
Returns the substring of s that starts at i and continues until j. i and j may be
negative. If j is absent, then it is assumed to be equal to –1, which is the
same as the string length. In particular, the call
string.sub(s,1,j)
returns a prefix s with length j, and
string.sub(s, -i)
returns a suffix s
with length i.
string.upper(s)
Returns a copy of the string s with all lowercase letters changed to
uppercase.
math.abs(x)
Returns the absolute value of the argument x.
math.acos(x)
Returns the principal value of the trigonometric arc cosine function of x.
math.asin(x)
Returns the principal value of the trigonometric arc sine function of x.
math.atan(x)
Returns the principal value of the trigonometric arc tangent function of x.
math.atan2(y,x)
Returns the principal value of the trigonometric arc tangent function of y/x.
math.ceil(x)
Returns the smallest floating-point number not less than x whose value is an exact
mathematical integer.