Skip to content

Array

Array is an ordered list of values, of which the index is starting from zero.

Properties

number Length

The Array length
1
2
local x = Array.Create("float3", 3)
print(x.Length)

Functions

Array Array.Create(string typeName, number length)

Returnsan array
Creates an instance of Array.
  • typeName The element type of the array.
  • length The length of the array.
1
local x = Array.Create("float3", 3)

table ToTable()

ReturnsLua table.
Convert Array to Lua ordinary arrays.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
local x = Array.Create("float3", 3)
x[0] = float3.New(1,1,1)
x[1] = float3.New(-2,-2,-2)
x[2] = float3.New(3,-2,1)
for i = 0, x.Length-1 do
    print("[array]", tostring(x[i]))
end
local t = x:ToTable()
for i, v in ipairs(t) do
    print("[table]", tostring(v))
end

void CopyTo(number startIndex, Array destination, number destinationStartIndex, number length)

Copy length elements of this array from startIndex and writes to destination from destinationStartIndex.
  • startIndex The start index of this array.
  • destination The array written to.
  • destinationStartIndex The start index of the destination.
  • length The copied length.
1
2
3
4
5
local is1 = Array.Create("integer", 4)
for i = 1, is1.Length do is1[i-1] = i end  -- is1: [1,2,3,4]
local is2 = Array.Create("integer", 6)
for i = 1, is2.Length do is2[i-1] = i end  -- is2: [1,2,3,4,5,6]
is1:CopyTo(1, is2, 3, 3)                   -- is2: [1,2,3,2,3,4]

void Reverse()

Reverses the array.
1
2
3
local is = Array.Create("integer", 4)
for i = 1, is.Length do is[i-1] = i end  -- is: [1,2,3,4]
is:Reverse()                             -- is: [4,3,2,1]

number IndexOf(table value)

ReturnsThe index.
Finds the first index of value. Returns the index of the value or -1 if value not found.
  • value The value.

number LastIndexOf(table value)

ReturnsThe index.
Finds the last index of value. Returns the index of the value or -1 if value not found.
  • value The value.