array
| Function Name | Parameter | Return | Explain |
| size | None | number | |
| clear | None | None | |
| add | T | boolean | |
| insert | number i, T | boolean | |
| remove | number i | boolean | |
| get | number i | T | |
| set | number i, T | boolean | |
| find | T, number start | boolean / number | return false if not found, otherwise return index of element. |
| sort | function comp | None | Sorts array elements in a given order, in-place,
from array[1] to array[n], where n
is the length of the table. If comp is given, then it must be
a function that receives two table elements, and returns true when the
first is less than the second (so that not comp(a[i+1],a[i])
will be true after the sort). If comp is not given, then the
standard Lua operator < is used instead.
The sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort. |
| append | array | None | |
| Lib Function | Parameter | Return | Explain |
| new | None | array |
T: any type of lua data
Usage example :
a=array.new()
a.add(3)
a.add('dog')
t={}
a.add(t)
a.add(true)
print(a[1]) --3
a.insert(1,'dog')
print(a[1]) --dog
print(a.find('dog')) --1
print(a.find('dog',2)) --3
print(a.size()) -- 5
a.remove(3)
print(a.size()) -- 4