/* The previously freed references form a linked list: t is the index of a first free index, or zero if list is empty; t] is the index of the second element; etc.  */
LUALIB_API int luaL_ref(lua_State *L, int t)
/* The previously freed references form a linked list: t is the index of a first free index, or zero if list is empty; t] is the index of the second element; etc.  */
LUALIB_API int luaL_ref(lua_State *L, int t)
{
    lua_pop(L, 1);
    return LUA_REFNIL;
  }
  t = lua_absindex(L, t);
  if (lua_rawgeti(L, t, freelist) == LUA_TNIL) {
    ref = 0;
    lua_pushinteger(L, 0);
    lua_rawseti(L, t, freelist);
  }
  else {
    lua_assert(lua_isinteger(L, -1));
    ref = (int)lua_tointeger(L, -1);
  }
  lua_pop(L, 1);
  if (ref != 0) {
    lua_rawgeti(L, t, ref);
    lua_rawseti(L, t, freelist);
  }
  else
    ref = (int)lua_rawlen(L, t) + 1;
  lua_rawseti(L, t, ref);
  return ref;
}