TArray
TArray is Unreal Engine’s array implementation.
The interface described below differs in several ways.
The first and most important difference is that it’s 1-indexed to match a Lua programmers expectation of a table-like structure.
The second difference is that it’s backed by FScriptArray instead of TArray<T> because Lua doesn’t have a template system.
The subtype T is resolved automatically at runtime whenever necessary.
Inheritance
Metamethods
__index
- Usage:
TArray[ArrayIndex] - Return type:
auto - Attempts to retrieve the value at the specified integer offset
ArrayIndexin the array. - Can return any type, you can use the
type()function on the returned value to figure out what Lua class it’s using (if non-trivial type).
__newindex
- Usage:
TArray[ArrayIndex] = NewValue - Attempts to set the value at the specified integer offset
ArrayIndexin the array toNewValue.
__len
- Usage:
#TArray - Return type:
integer - Returns the number of current elements in the array.
Methods
GetArrayAddress()
- Return type:
integer - Returns: the address in memory where the
TArraystruct is located.
GetArrayNum()
- Return type:
integer - Returns: the number of current elements in the array.
GetArrayMax()
- Return type:
integer - Returns: the maximum number of elements allowed in this array (aka capacity).
GetArrayDataAddress()
- Return type:
integer - Returns: the address in memory where the data for this array is stored.
Empty()
- Clears the array.
ForEach(function Callback)
- Iterates the entire
TArrayand calls the callback function for each element in the array. - The callback params are:
integer index,RemoteUnrealParam elem|LocalUnrealParam elem. - Use
elem:get()andelem:set()to access/mutate an array element. - The callback can optionally return
trueto break out of the loop early.