| 593 | |
| 594 | |
| 595 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
| 596 | int ref; |
| 597 | if (lua_isnil(L, -1)) { |
| 598 | lua_pop(L, 1); /* remove from stack */ |
| 599 | return LUA_REFNIL; /* 'nil' has a unique fixed reference */ |
| 600 | } |
| 601 | t = lua_absindex(L, t); |
| 602 | lua_rawgeti(L, t, freelist); /* get first free element */ |
| 603 | ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */ |
| 604 | lua_pop(L, 1); /* remove it from stack */ |
| 605 | if (ref != 0) { /* any free element? */ |
| 606 | lua_rawgeti(L, t, ref); /* remove it from list */ |
| 607 | lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */ |
| 608 | } |
| 609 | else /* no free elements */ |
| 610 | ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */ |
| 611 | lua_rawseti(L, t, ref); |
| 612 | return ref; |
| 613 | } |
| 614 | |
| 615 | |
| 616 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
nothing calls this directly
no test coverage detected