Module Table
Table operations
Standard Lua data structure manipulation on maps (key/value) and arrays.
Functions
table.concat (table, sep, i, j) | Given an array where all elements are strings or numbers, returns `table[i]..sep..table[i+1] ... |
table.insert (table, pos, value) | Inserts element value at position pos in table, shifting up
other elements to open space, if necessary. |
table.maxn (table) | Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices. |
table.remove (table, pos) | Removes from table the element at position pos , shifting down other
elements to close the space, if necessary. |
table.sort (table, comp) | Sorts table elements in a given order,
in-place, from table[1] to table[n] , where n is the length of the
table. |
Functions
- table.concat (table, sep, i, j)
-
Given an array where all elements are strings or numbers, returns
table[i]..sep..table[i+1] ... sep..table[j]
. The default value forsep
is the empty string, the default fori
is 1, and the default forj
is the length of the table. Ifi
is greater thanj
, returns the empty string.Parameters:
- table
- sep
- i
- j
- table.insert (table, pos, value)
-
Inserts element
value
at positionpos
in table, shifting up other elements to open space, if necessary. The default value forpos
isn+1
, wheren
is the length of the table (see ยง2.5.5), so that a calltable.insert(t,x)
insertsx
at the end of tablet
.Parameters:
- table
- pos
- value
- table.maxn (table)
-
Returns the largest positive numerical index of the given table, or
zero if the table has no positive numerical indices. (To do its job this
function does a linear traversal of the whole table.)
Parameters:
- table
- table.remove (table, pos)
-
Removes from table the element at position
pos
, shifting down other elements to close the space, if necessary. Returns the value of the removed element. The default value forpos
isn
, wheren
is the length of the table, so that a calltable.remove(t)
removes the last element of tablet
.Parameters:
- table
- pos
- table.sort (table, comp)
-
Sorts table elements in a given order,
in-place, from
table[1]
totable[n]
, wheren
is the length of the table. Ifcomp
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 thatnot comp(a[i+1],a[i])
will be true after the sort). Ifcomp
is not given, then the '<' operator will be used.Parameters:
- table
- comp