MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaL_ref

Function luaL_ref

3rd/lua-5.4.3/src/lauxlib.c:660–685  ·  view source on GitHub ↗

** The previously freed references form a linked list: ** t[freelist] is the index of a first free index, or zero if list is ** empty; t[t[freelist]] is the index of the second element; etc. */

Source from the content-addressed store, hash-verified

658** empty; t[t[freelist]] is the index of the second element; etc.
659*/
660LUALIB_API int luaL_ref (lua_State *L, int t) {
661 int ref;
662 if (lua_isnil(L, -1)) {
663 lua_pop(L, 1); /* remove from stack */
664 return LUA_REFNIL; /* 'nil' has a unique fixed reference */
665 }
666 t = lua_absindex(L, t);
667 if (lua_rawgeti(L, t, freelist) == LUA_TNIL) { /* first access? */
668 ref = 0; /* list is empty */
669 lua_pushinteger(L, 0); /* initialize as an empty list */
670 lua_rawseti(L, t, freelist); /* ref = t[freelist] = 0 */
671 }
672 else { /* already initialized */
673 lua_assert(lua_isinteger(L, -1));
674 ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
675 }
676 lua_pop(L, 1); /* remove element from stack */
677 if (ref != 0) { /* any free element? */
678 lua_rawgeti(L, t, ref); /* remove it from list */
679 lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
680 }
681 else /* no free elements */
682 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
683 lua_rawseti(L, t, ref);
684 return ref;
685}
686
687
688LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {

Callers

nothing calls this directly

Calls 5

lua_absindexFunction · 0.85
lua_rawgetiFunction · 0.85
lua_pushintegerFunction · 0.85
lua_rawsetiFunction · 0.85
lua_isintegerFunction · 0.70

Tested by

no test coverage detected