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

Function ReleaseHash

engine/script/src/script_hash.cpp:246–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 1

DoDeleteInstanceFunction · 0.85

Calls 8

lua_gettopFunction · 0.85
lua_rawgetiFunction · 0.85
lua_isuserdataFunction · 0.85
lua_removeFunction · 0.85
luaL_unrefFunction · 0.85
GetScriptContextFunction · 0.70
assertFunction · 0.50
GetMethod · 0.45

Tested by

no test coverage detected