Difference between revisions of "UM:NetXMS Scripting Language (NXSL)"

m (Added category)
Line 204: Line 204:
A ''key'' must be a non-negative integer. When an array is created, its size is not specified and its map can have empty spots in it. For example, an array can have a element with a ''0'' key and an element with ''4'' key and no keys in-between. Attempting to access an array key which has not been defined is the same as accessing any other undefined variable: the result will be <tt>NULL</tt>.
A ''key'' must be a non-negative integer. When an array is created, its size is not specified and its map can have empty spots in it. For example, an array can have a element with a ''0'' key and an element with ''4'' key and no keys in-between. Attempting to access an array key which has not been defined is the same as accessing any other undefined variable: the result will be <tt>NULL</tt>.


Array elements can be accessed using [''index''] operator. For example, to access element with index 3 of array ''a'' you should use
<syntaxhighlight lang="c">
a[3];
</syntaxhighlight>
== Array Initialization ==
New array can be created in two ways. First is to use '''array''' operator:
<syntaxhighlight lang="c">
array a;
</syntaxhighlight>
This statement will create empty array and assign reference to it to variable ''a''.
Second way is to use %( ) construct to create array already populated with values:
<syntaxhighlight lang="c">
a = %(1, 2, 3, 4);
</syntaxhighlight>
This statement will create array with four elements at positions 0, 1, 2, and 3, and assign reference to this array to variable ''a''. Array initialization can also be used directly in expressions, like this:
<syntaxhighlight lang="c">
sub f()
{
  return %(2, "text", %(1, 2, 3));
}
</syntaxhighlight>
In this example function ''f'' returns array of 3 elements - number, text, and another array of 3 numeric elements.


= Operators =
= Operators =
683

edits