MCPcopy Create free account
hub / github.com/defold/defold / Hash_gc

Function Hash_gc

engine/script/src/script_hash.cpp:397–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395 };
396
397 static int Hash_gc(lua_State* L)
398 {
399 dmhash_t hash = *(dmhash_t*)lua_touserdata(L, 1);
400 HContext context = dmScript::GetScriptContext(L);
401 if (context)
402 {
403 int* refp = context->m_HashInstances.Get(hash);
404 if (refp && context->m_ContextWeakTableRef != LUA_NOREF)
405 {
406 lua_rawgeti(L, LUA_REGISTRYINDEX, context->m_ContextWeakTableRef);
407 // [-1] weak_table
408 PushHashWeakTableKey(L, hash);
409 // [-2] weak_table
410 // [-1] key
411 lua_rawget(L, -2);
412 // [-2] weak_table
413 // [-1] value or nil
414 if (lua_isnil(L, -1))
415 {
416 context->m_HashInstances.Erase(hash);
417 dmHashReverseErase64(hash);
418 }
419 lua_pop(L, 2);
420 }
421 }
422 return 0;
423 }
424
425 void InitializeHash(lua_State* L)
426 {

Callers

nothing calls this directly

Calls 8

lua_touserdataFunction · 0.85
lua_rawgetiFunction · 0.85
PushHashWeakTableKeyFunction · 0.85
lua_rawgetFunction · 0.85
dmHashReverseErase64Function · 0.85
GetScriptContextFunction · 0.70
GetMethod · 0.45
EraseMethod · 0.45

Tested by

no test coverage detected