| 10691 | |
| 10692 | |
| 10693 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
| 10694 | int ref; |
| 10695 | t = abs_index(L, t); |
| 10696 | if (lua_isnil(L, -1)) { |
| 10697 | lua_pop(L, 1); /* remove from stack */ |
| 10698 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ |
| 10699 | } |
| 10700 | lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ |
| 10701 | ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ |
| 10702 | lua_pop(L, 1); /* remove it from stack */ |
| 10703 | if (ref != 0) { /* any free element? */ |
| 10704 | lua_rawgeti(L, t, ref); /* remove it from list */ |
| 10705 | lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ |
| 10706 | } |
| 10707 | else { /* no free elements */ |
| 10708 | ref = (int)lua_objlen(L, t); |
| 10709 | ref++; /* create new reference */ |
| 10710 | } |
| 10711 | lua_rawseti(L, t, ref); |
| 10712 | return ref; |
| 10713 | } |
| 10714 | |
| 10715 | |
| 10716 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
no test coverage detected