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

Function PushHash

engine/script/src/script_hash.cpp:204–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202 }
203
204 void PushHash(lua_State* L, dmhash_t hash)
205 {
206 int top = lua_gettop(L);
207
208 HContext context = dmScript::GetScriptContext(L);
209
210 dmHashTable64<int>* instances = &context->m_HashInstances;
211 int* refp = instances->Get(hash);
212
213 if (refp)
214 {
215 lua_rawgeti(L, LUA_REGISTRYINDEX, context->m_ContextWeakTableRef);
216 // [-1] weak_table
217 PushHashWeakTableKey(L, hash);
218 // [-2] weak_table
219 // [-1] key
220 lua_rawget(L, -2);
221 // [-2] weak_table
222 // [-1] value or nil
223 if (lua_isnil(L, -1))
224 {
225 lua_pop(L, 1); // remove nil
226 //[-1] weak_table
227
228 // Create new userdata and re-register it
229 lua_pop(L, 1); // remove weak_table
230 CreateLuaHashUserdata(L, hash);
231 }
232 else
233 {
234 lua_remove(L, -2); // remove weak_table
235 // [-1] hash
236 }
237 }
238 else
239 {
240 CreateLuaHashUserdata(L, hash);
241 }
242
243 assert(top + 1 == lua_gettop(L));
244 }
245
246 void ReleaseHash(lua_State* L, dmhash_t hash)
247 {

Callers 15

ScriptResolvePathFunction · 0.85
Script_GetParentFunction · 0.85
Script_GetIdFunction · 0.85
PropertiesToLuaTableFunction · 0.85
HandleMessageFunction · 0.85
CompScriptOnInputFunction · 0.85
LuaPushVarFunction · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85
Lua_SpawnFunction · 0.85

Calls 9

lua_gettopFunction · 0.85
lua_rawgetiFunction · 0.85
PushHashWeakTableKeyFunction · 0.85
lua_rawgetFunction · 0.85
CreateLuaHashUserdataFunction · 0.85
lua_removeFunction · 0.85
GetScriptContextFunction · 0.70
assertFunction · 0.50
GetMethod · 0.45

Tested by 11

TEST_FFunction · 0.68
TEST_FFunction · 0.68
Lua_SpawnFunction · 0.68
TestHashMethod · 0.68
TEST_FFunction · 0.68
TEST_FFunction · 0.68
TestResolvePathFunction · 0.68
UserdataErrorFuncFunction · 0.68
LuaCallbackCustomArgsFunction · 0.68
ResolvePathCallbackFunction · 0.68
ResolvePathCallbackFunction · 0.68