Skip to main content

Module func

Module func 

Source
Expand description

Auxiliary functions to manipulate prototypes and closures.

Port of reference/lua-5.4.7/src/lfunc.c (295 lines, 16 functions). The companion header lfunc.h is merged here per PORTING.md §1.

§Design notes

The C implementation uses two intrusive linked lists managed through pointer fields embedded in stack slots and upvalue objects:

  • openupval: a singly-linked list of UpVals sorted by stack level (highest first), threaded through UpVal.u.open.next / .previous.
  • tbclist: a to-be-closed variable list encoded as unsigned short delta offsets stored inside StackValue.tbclist.delta.

Both are replaced in the Rust port:

  • openupvalLuaState.openupval: Vec<GcRef<UpVal>> (descending by StackIdx).
  • tbclistLuaState.tbclist: Vec<StackIdx> (back = most recent entry).

The delta-encoding machinery (MAXDELTA, dummy nodes) is an artifact of the u16 delta field and is entirely superseded by the Vec<StackIdx> model.

Structs§

CallInfoIdx
Index into the call-info stack.
StackIdx
Index into the Lua value stack. Never a pointer or borrow. Stack reallocates; only indices are stable across mutations.