Array
Array is an ordered list of values, of which the index is starting from zero.Properties
number Length
The Array length
local x = Array.Create("float3", 3)
print(x.Length)
Functions
Array Array.Create(string typeName, number length)
Returnsan array
Creates an instance of Array.typeNameThe element type of the array.lengthThe length of the array.
local x = Array.Create("float3", 3)
table ToTable()
ReturnsLua table.
Convert Array to Lua ordinary arrays.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.
startIndexThe start index of this array.destinationThe array written to.destinationStartIndexThe start index of thedestination .lengthThe copied length.
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.
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.valueThe 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.valueThe value.