| 527 | |
| 528 | |
| 529 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
| 530 | int ref; |
| 531 | t = abs_index(L, t); |
| 532 | if (lua_isnil(L, -1)) { |
| 533 | lua_pop(L, 1); /* remove from stack */ |
| 534 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ |
| 535 | } |
| 536 | lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ |
| 537 | ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ |
| 538 | lua_pop(L, 1); /* remove it from stack */ |
| 539 | if (ref != 0) { /* any free element? */ |
| 540 | lua_rawgeti(L, t, ref); /* remove it from list */ |
| 541 | lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ |
| 542 | } |
| 543 | else { /* no free elements */ |
| 544 | ref = (int)lua_objlen(L, t); |
| 545 | ref++; /* create new reference */ |
| 546 | } |
| 547 | lua_rawseti(L, t, ref); |
| 548 | return ref; |
| 549 | } |
| 550 | |
| 551 | |
| 552 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
nothing calls this directly
no test coverage detected