| 244 | } |
| 245 | |
| 246 | void ReleaseHash(lua_State* L, dmhash_t hash) |
| 247 | { |
| 248 | int top = lua_gettop(L); |
| 249 | |
| 250 | HContext context = dmScript::GetScriptContext(L); |
| 251 | dmHashTable64<int>* instances = &context->m_HashInstances; |
| 252 | int* refp = instances->Get(hash); |
| 253 | if (!refp) |
| 254 | { |
| 255 | assert(top == lua_gettop(L)); |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | int ref = *refp; |
| 260 | // Retrieve the value from the strong table |
| 261 | lua_rawgeti(L, LUA_REGISTRYINDEX, context->m_ContextTableRef); |
| 262 | // [-1] context_table |
| 263 | lua_rawgeti(L, -1, ref); |
| 264 | // [-2] context_table |
| 265 | // [-1] value |
| 266 | |
| 267 | if (!lua_isuserdata(L, -1)) |
| 268 | { |
| 269 | lua_pop(L, 2); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | lua_remove(L, -2); |
| 274 | // [-1] value |
| 275 | |
| 276 | // Remove value from strong table |
| 277 | lua_rawgeti(L, LUA_REGISTRYINDEX, context->m_ContextTableRef); |
| 278 | // [-2] value |
| 279 | // [-1] context_table |
| 280 | luaL_unref(L, -1, ref); |
| 281 | lua_pop(L, 2); |
| 282 | // stack balanced |
| 283 | |
| 284 | assert(top == lua_gettop(L)); |
| 285 | } |
| 286 | |
| 287 | dmhash_t CheckHash(lua_State* L, int index) |
| 288 | { |
no test coverage detected