pub fn lua_ref(state: &mut LuaState, t: i32) -> Result<i32, LuaError>Expand description
Store the value at the top of the stack in table t and return a unique
integer reference. If the value is nil, returns LUA_REFNIL without
modifying the table.
The free-list head at [freelist_ref]’s index counts as “initialized”
once it holds a Number, matching 5.5’s explicit LUA_TNUMBER check
(reference/lua-5.5.0/src/lauxlib.c) rather than 5.1-5.4’s plain nil
check: 5.5’s set_versioned_registry_slots pre-seeds registry[1] with
false (not nil) as the free-list’s “uninitialized” sentinel, and a
nil-only check would misread that sentinel as already-initialized. The
two checks agree on 5.1-5.4 (the head there is always either nil or a
Number), so a single version-free comparison covers every version.