pub fn gmatch_aux(state: &mut LuaState) -> Result<usize, LuaError>Expand description
Continuation function for string.gmatch iterator closure.
PORT NOTE: The C version stores GMatchState inside a heap-allocated
userdata referenced by upvalue 3, then mutates fields via the raw pointer
each iteration. Our Phase-A LuaCClosure.upvalues is immutable, so the
iterator state lives in a Lua table referenced by upvalue 1 with
integer-keyed slots:
t[1] = source bytes (string), t[2] = pattern bytes (string),
t[3] = current source position (1-based; equals lastmatch after a
successful match), t[4] = end of last match (0 ≡ NULL in C, meaning
“no match yet”).
PERF NOTE: The previous version pushed the upvalue table onto the stack
and then issued six raw_geti / raw_seti calls plus four to_lua_string
/ to_integer_x reads — each of which re-resolves the stack index via
index_to_value. That made index_to_value the #1 non-algorithm frame in
string_ops_long at 9.4% of wall. The current version resolves the
upvalue once via value_at, extracts the GcRef<LuaTable>, and reads /
writes its integer-keyed slots directly through LuaTableRefExt. This is
the same shape as C-Lua’s luaH_getint / luaH_setint direct table ops
against the embedded GMatchState struct fields — no stack roundtrip
per probe.