Expand description
Lua table implementation (array + hash hybrid).
Canonical port of reference/lua-5.4.7/src/ltable.c. Lives in
lua-types because LuaValue::Table(GcRef<LuaTable>) is defined here
and the table storage must be reachable without depending on
lua-vm. The crate lua_unsafe = "forbid" lint is preserved.
§Interior mutability
GcRef<T> only yields &T on deref, so the mutable algorithms in
C-Lua’s ltable.c (which write through Table *) must operate
through a RefCell. The split is:
LuaTable— outer handle. All public methods take&self.TableInner— storage + algorithms. All mutating methods are&mut TableInnerand are reached viainner.borrow_mut().
The hash part uses Brent’s variation of chained scatter tables. The key invariant: if an element is not in its main position (the slot its hash maps to), the colliding element is in its own main position.
Structs§
- LuaTable
- A Lua table: hybrid array + hash map.
- Table
Flags - Bitfield for a
LuaTable: lower bits record absent fast-access metamethods; bit 7 encodes whetheralimitis the real array size. - Table
Inner - Hybrid array + hash storage backing a
LuaTable. - Table
Node - One node in a table’s hash part.
Enums§
- Table
Slot Ref - Internal slot reference returned by the “get” family of functions.
Constants§
- ARRAY_
GROW_ CAP - Soft cap on array growth in a single
raw_setcall. - MAXASIZE
- Maximum size of the array part.
- MAXHBITS
- Largest
ksuch that2^kfits in a signedi32minus one (hash part). - TOTAL_
GROW_ CAP - Soft cap on total entries (array + hash) used to emulate C-Lua’s
malloc-NULL termination of unboundedfor i = 1, math.huge do a[i] = ... endloops. C-Lua hits real malloc failure at multi-gigabyte allocations; we raiseLuaError::Memory(which pcall catches as"not enough memory") once the table exceeds this size. Sized well above any realistic test workload (big.luauses ~264K entries) while bounded enough thatheavy.luaterminates within the harness timeout.