![background image](http://html2.mh-extra.com/html/keithley/2657a/2657a_reference-manual_4007750275.webp)
Section 6: Instrument programming
Model 2657A High Power System SourceMeter® Instrument Reference Manual
6-26
2657A-901-01 Rev. B/December 2012
Lua memory management
Lua automatically manages memory, which means you do not have to allocate memory for new
objects and free it when the objects are no longer needed. Lua occasionally runs a garbage collector
to collect all objects that are no longer accessible from Lua. All objects in Lua are subject to automatic
management, including tables, variables, functions, threads, and strings.
Lua uses two numbers to control its garbage-collection cycles. One number counts how many bytes
of dynamic memory Lua is using; the other is a threshold. When the number of bytes crosses the
threshold, Lua runs the garbage collector, which reclaims the memory of all inaccessible objects. The
byte counter is adjusted and the threshold is reset to twice the new value of the byte counter.
String library functions
This library provides generic functions for string manipulation, such as finding and extracting
substrings. When indexing a string in Lua, the first character is at position 1 (not 0, as in ANSI C).
Indices may be negative and are interpreted as indexing backward from the end of the string. Thus,
the last character is at position
−
1, and so on.
String library functions
Function Description
string.byte(
s
)
string.byte(
s
,
i
)
string.byte(
s
,
i
,
j
)
Returns the internal numeric codes of the characters
s
[
i
],
s
[
i
+1],
···
,
s
[
j
]
. The default value for
i
is
1
; the default
value for
j
is
i
.
string.char(
···
)
Receives zero or more integers. Returns a string with length equal
to the number of arguments, in which each character has the
internal numeric code equal to its corresponding argument.
string.format(
formatstring
,
...)
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
printf
family of standard C functions. The only differences are that the
modifiers
*
,
l
,
L
,
n
,
p
, and
h
are not supported and there is an
extra option,
q
. The
q
option formats a string in a form suitable to
be safely read back by the Lua interpreter; the string is written
between double quotes, and all double quotes, newlines,
embedded zeros, and backslashes in the string are correctly
escaped when written.
For example, the call:
string.format('%q', 'a string with "quotes" and
\n new line')
will produce the string:
"a string with \"quotes\" and \
new line"
The options
c
,
d
,
E
,
e
,
f
,
g
,
G
,
i
,
o
,
u
,
X
, and
x
all expect a number
as argument.
q
and
s
expect a string. This function does not
accept string values containing embedded zeros, except as
arguments to the
q
option.
string.len(
s
)
Receives a string and returns its length. The empty string
""
has
length
0
. Embedded zeros are counted, so
"a\000bc\000"
has
length
5
.
Содержание 2657A
Страница 3: ......