| 642 | |
| 643 | |
| 644 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
| 645 | int ref; |
| 646 | if (lua_isnil(L, -1)) { |
| 647 | lua_pop(L, 1); /* remove from stack */ |
| 648 | return LUA_REFNIL; /* 'nil' has a unique fixed reference */ |
| 649 | } |
| 650 | t = lua_absindex(L, t); |
| 651 | lua_rawgeti(L, t, freelist); /* get first free element */ |
| 652 | ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */ |
| 653 | lua_pop(L, 1); /* remove it from stack */ |
| 654 | if (ref != 0) { /* any free element? */ |
| 655 | lua_rawgeti(L, t, ref); /* remove it from list */ |
| 656 | lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */ |
| 657 | } |
| 658 | else /* no free elements */ |
| 659 | ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */ |
| 660 | lua_rawseti(L, t, ref); |
| 661 | return ref; |
| 662 | } |
| 663 | |
| 664 | |
| 665 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
no test coverage detected