| 504 | |
| 505 | |
| 506 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
| 507 | int ref; |
| 508 | t = abs_index(L, t); |
| 509 | if (lua_isnil(L, -1)) { |
| 510 | lua_pop(L, 1); /* remove from stack */ |
| 511 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ |
| 512 | } |
| 513 | lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ |
| 514 | ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ |
| 515 | lua_pop(L, 1); /* remove it from stack */ |
| 516 | if (ref != 0) { /* any free element? */ |
| 517 | lua_rawgeti(L, t, ref); /* remove it from list */ |
| 518 | lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ |
| 519 | } |
| 520 | else { /* no free elements */ |
| 521 | ref = (int)lua_objlen(L, t); |
| 522 | ref++; /* create new reference */ |
| 523 | } |
| 524 | lua_rawseti(L, t, ref); |
| 525 | return ref; |
| 526 | } |
| 527 | |
| 528 | |
| 529 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
no test coverage detected