Skip to main content

array

Availability

Device + Agent

Description

Squirrel’s array library provides a set of tools for the manipulation of array variables and the items they contain.

Arrays can contain any Squirrel data type, including arrays themselves, and the items within an array need not be of the same type. However, if functions and/or objects are inserted into the array, the array can no longer be serialized (see the Developer Guide ‘Serializable Squirrel’ for more information), which has implications for the array’s ability to be sent from agent to device or vice versa, and determines whether it can be saved in persistent storage.

Referencing

Arrays are accessed by reference, and adding an array reference to another entity, such as a table or another array, or passing it into a function parameter, does not add a copy of the array but a reference to it.

For example, the following code

local arrayOne = [];
local tableOne = {};
local tableTwo = {};

tableOne.myArray <- arrayOne;
tableTwo.anArray <- arrayOne;

Causes the two tables tableOne and tableTwo to each contain a reference to a single, shared array, arrayOne. This is the case even though the two tables identify that same array with their own, different keys.

Further Information

For more guidance on using arrays, please see the Squirrel Programming Guide.

Member Entities

The array object has the following member methods:

The array object has the following member function:

  • array()Creates an array of the required size