CoreModules.Table) provides functions for manipulating Lua tables, which serve as arrays, dictionaries, and objects in Lua.
Array Functions
table.insert(list, [pos,] value)
Inserts an element into a table array.list- The table to modifypos- Optional insertion position (default: end of array)value- Value to insert
- Position out of bounds (< 1 or > #list + 1)
- Wrong number of arguments
table.remove(list [, pos])
Removes and returns an element from a table array.list- The table to modifypos- Optional position (default: end of array)
table.pack(…)
Creates a table with all arguments, including a count.n with the count
table.unpack(list [, i [, j]])
Returns elements from a table as multiple return values.list- The table to unpacki- Start index (default: 1)j- End index (default:#list)
unpack() function.
String Functions
table.concat(list [, sep [, i [, j]]])
Concatenates table elements into a string.list- Table with string or number elementssep- Separator string (default:"")i- Start index (default: 1)j- End index (default:#list)
Sorting
table.sort(list [, comp])
Sorts table elements in-place.list- Table to sortcomp- Optional comparison function(a, b) -> boolean- Should return
trueifashould come beforeb - Default:
a < busing<operator or__ltmetamethod
- Should return
- Modifies the table in-place
- Uses the
__ltmetamethod if available - Sort is not guaranteed to be stable
Length Calculation
The table module respects the__len metamethod when determining table length:
concat, unpack, insert, remove) will call the __len metamethod if present.
Comparison with __lt Metamethod
Thetable.sort() function respects the __lt (less than) metamethod:
Global Functions
SolarSharp provides global aliases forpack and unpack (Lua 5.1 compatibility):