Array
Description:
An array data structure that supports various operations. The Array record is designed to be 1-based indexing, which means that the first item in the array has an index of 1. This is the same behavior of Lua table used as an array.
Class Object: Array Class.
Inherits from: Object.
count
Type: Readonly Field.
Description:
The number of items in the array.
Signature:
const count: integer
empty
Type: Readonly Field.
Description:
Whether the array is empty or not.
Signature:
const empty: boolean
addRange
Type: Function.
Description:
Adds all items from another array to the end of this array.
Signature:
addRange: function(self: Array, other: Array)
Parameters:
Parameter | Type | Description |
---|---|---|
other | Array | Another array object. |
removeFrom
Type: Function.
Description:
Removes all items from this array that are also in another array.
Signature:
removeFrom: function(self: Array, other: Array)
Parameters:
Parameter | Type | Description |
---|---|---|
other | Array | Another array object. |
clear
Type: Function.
Description:
Removes all items from the array.
Signature:
clear: function(self: Array)
reverse
Type: Function.
Description:
Reverses the order of the items in the array.
Signature:
reverse: function(self: Array)
shrink
Type: Function.
Description:
Removes any empty slots from the end of the array. Used for release the unused memory this array holds.
Signature:
shrink: function(self: Array)
swap
Type: Function.
Description:
Swaps the items at two given indices.
Signature:
swap: function(self: Array, indexA: integer, indexB: integer)
Parameters:
Parameter | Type | Description |
---|---|---|
indexA | integer | The first index. |
indexB | integer | The second index. |
removeAt
Type: Function.
Description:
Removes the item at the given index.
Signature:
removeAt: function(self: Array, index: integer): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
index | integer | The index to remove. |
Returns:
Return Type | Description |
---|---|
boolean | True if an item was removed, false otherwise. |
fastRemoveAt
Type: Function.
Description:
Removes the item at the given index without preserving the order of the array.
Signature:
fastRemoveAt: function(self: Array, index: integer): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
index | integer | The index to remove. |
Returns:
Return Type | Description |
---|---|
boolean | True if an item was removed, false otherwise. |
each
Type: Function.
Description:
Calls a given function for each item in the array.
Signature:
each: function(self: Array, func: function(Object): boolean): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
func | function | The function to call for each item. Should return false to continue iteration, true to stop. |
Returns:
Return Type | Description |
---|---|
boolean | False if the iteration completed, true if it was interrupted by the function. |
first
Type: Readonly Field.
Description:
The first item in the array.
Signature:
const first: Item
last
Type: Readonly Field.
Description:
The last item in the array.
Signature:
const last: Item
randomObject
Type: Readonly Field.
Description:
A random item from the array.
Signature:
const randomObject: Item
set
Type: Function.
Description:
Sets the item at the given index.
Signature:
set: function(self: Array, index: integer, item: Item)
Parameters:
Parameter | Type | Description |
---|---|---|
index | integer | The index to set, should be 1 based. |
item | Item | The new item value. |
get
Type: Function.
Description:
Gets the item at the given index.
Signature:
get: function(self: Array, index: integer): Item
Parameters:
Parameter | Type | Description |
---|---|---|
index | integer | The index to get, should be 1 based. |
Returns:
Return Type | Description |
---|---|
Item | The item value. |
add
Type: Function.
Description:
Adds an item to the end of the array.
Signature:
add: function(self: Array, item: Item)
Parameters:
Parameter | Type | Description |
---|---|---|
item | Item | The item to add. |
insert
Type: Function.
Description:
Inserts an item at the given index, shifting other items to the right.
Signature:
insert: function(self: Array, index: integer, item: Item)
Parameters:
Parameter | Type | Description |
---|---|---|
index | integer | The index to insert at. |
item | Item | The item to insert. |
contains
Type: Function.
Description:
Checks whether the array contains a given item.
Signature:
contains: function(self: Array, item: Item): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
item | Item | The item to check. |
Returns:
Return Type | Description |
---|---|
boolean | True if the item is found, false otherwise. |
index
Type: Function.
Description:
Gets the index of a given item.
Signature:
index: function(self: Array, item: Item): integer
Parameters:
Parameter | Type | Description |
---|---|---|
item | Item | The item to search for. |
Returns:
Return Type | Description |
---|---|
integer | The index of the item, or 0 if it is not found. |
removeLast
Type: Function.
Description:
Removes and returns the last item in the array.
Signature:
removeLast: function(self: Array): Item
Returns:
Return Type | Description |
---|---|
Item | The last item removed from the array. |
fastRemove
Type: Function.
Description:
Removes the first occurrence of a given item from the array without preserving order.
Signature:
fastRemove: function(self: Array, item: Item): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
item | Item | The item to remove. |
Returns:
Return Type | Description |
---|---|
boolean | True if the item was found and removed, false otherwise. |
__index
Type: Metamethod.
Description:
Metamethod to access the item at the given index using the [] operator.
Signature:
metamethod __index: function(self: Array, index: integer): Item
Parameters:
Parameter | Type | Description |
---|---|---|
index | integer | The index to get, should be 1 based. |
Returns:
Return Type | Description |
---|---|
Item | The item value. |
__newindex
Type: Metamethod.
Description:
Metamethod to set the item at the given index using the [] operator.
Signature:
metamethod __newindex: function(self: Array, index: integer, item: Item)
Parameters:
Parameter | Type | Description |
---|---|---|
index | integer | The index to set, should be 1 based. |
item | Item | The new item value. |
__len
Type: Metamethod.
Description:
Metamethod to get the length of the array using the # operator.
Signature:
metamethod __len: function(self: Array): integer
Returns:
Return Type | Description |
---|---|
integer | The length of the array. |