| 479 | |
| 480 | |
| 481 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
| 482 | int ref; |
| 483 | t = abs_index(L, t); |
| 484 | if (lua_isnil(L, -1)) { |
| 485 | lua_pop(L, 1); /* remove from stack */ |
| 486 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ |
| 487 | } |
| 488 | lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ |
| 489 | ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ |
| 490 | lua_pop(L, 1); /* remove it from stack */ |
| 491 | if (ref != 0) { /* any free element? */ |
| 492 | lua_rawgeti(L, t, ref); /* remove it from list */ |
| 493 | lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ |
| 494 | } |
| 495 | else { /* no free elements */ |
| 496 | ref = (int)lua_objlen(L, t); |
| 497 | ref++; /* create new reference */ |
| 498 | } |
| 499 | lua_rawseti(L, t, ref); |
| 500 | return ref; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
nothing calls this directly
no test coverage detected