Expand description
Lua table standard library.
Provides: table.concat, table.insert, table.move, table.pack,
table.remove, table.sort, table.unpack.
C source: reference/lua-5.4.7/src/ltablib.c.
Constants§
- TABLE_
FUNCS - The core
tableroster shared by 5.2-5.5.moveis filtered out for 5.2 (a 5.3 addition) andmove/pack/unpackfor 5.1 byopen_table, which also layers the version-specific extras (5.1 legacy, 5.5create) on top.
Functions§
- concat
table.concat(t, [sep, [i, [j]]]). Joinst[i..j](defaultsi=1,j=#t) withsep(default empty) into one string. Each element must be a string or number; the first that is not raises through [add_field].- create
table.create(nseq [, nrec])— Lua 5.5 addition (specs/research/5.5-upstream-delta.md§5,ltablib.c).- insert
table.insert(t, [pos,] v). With two args, appendsvat border+1. With three, insertsvatpos(1 <= pos <= border+1) after shifting the tail up by one; any other arity raises “wrong number of arguments to ‘insert’”. The bounds check uses a wrapping unsigned subtract sopos <= 0is rejected alongsidepos > border+1. Noteborderhere is#t, which honors a__lenmetamethod on 5.2+ and uses the primitive length on 5.1.- open_
table - Builds the
tablelibrary table for the running version. The base roster isTABLE_FUNCS, from which 5.1 and 5.2 drop the functions they lack and onto which 5.1’s legacy roster and 5.5’screateare layered. The per-version deltas below are each verified against that version’s reference binary. - pack
table.pack(...). Creates a new table with the arguments at integer keys1..nandt.nset to the literal argument countn— holes and trailing nils included, so.nrecovers an arity that a#tborder would lose (pinned byv52_plus_pack_n_field_*). A 5.2 addition.- remove
table.remove(t, [pos]). Removes and returnst[pos](default: the last element,#t), shifting the tail down to close the gap.- sort
table.sort(t, [comp]): sortstin place usingcomp, or the default<operator ifcompis absent.- tmove
table.move(a1, f, e, t, [a2]). Copiesa1[f..e]intoa2[t..](ora1[t..]ifa2is absent), reading source slots through__indexand writing destinations through__newindexone element at a time. To survive an overlapping in-place range, it copies FORWARD (increasing index) when the destination is clear of the source’s tail (t > e || t <= f, or a distinct destination table) and BACKWARD (decreasing) otherwise — the order pinned byv53_plus_move_*. Returns the destination table. A 5.3 addition.- unpack
table.unpack(t, [i, [j]]). Pushest[i], t[i+1], …, t[j](defaultsi=1,j=#t) and returns the count. Ani > erange is empty (zero results); a span ofINT_MAXor more — including the i64-extreme wrap wheree - ioverflows to a huge unsigned value — raises “too many results to unpack” rather than attempting the push (pinned byv52_plus_unpack_*/v53_plus_unpack_*). A 5.2 addition.