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

Function DestroyCallback

engine/script/src/script.cpp:1893–1935  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1891 }
1892
1893 void DestroyCallback(LuaCallbackInfo* cbk)
1894 {
1895 lua_State* L = cbk->m_L;
1896 DM_LUA_STACK_CHECK(L, 0);
1897
1898 if(cbk->m_ContextTableRef != LUA_NOREF)
1899 {
1900 lua_rawgeti(L, LUA_REGISTRYINDEX, cbk->m_ContextTableRef);
1901 if (lua_type(L, -1) == LUA_TTABLE)
1902 {
1903 if (IsCallbackInstanceValid(cbk))
1904 {
1905 // We do not use dmScript::Unref for refs in the context local table as we don't
1906 // want to count those refs the ref debug count shown in the profiler
1907 luaL_unref(L, -1, cbk->m_Self);
1908 luaL_unref(L, -1, cbk->m_Callback);
1909 }
1910 else
1911 {
1912 cbk->m_UniqueScriptId = INVALID_SCRIPT_ID;
1913 }
1914 }
1915
1916 // For the callback (that can actually outlive the script instance)
1917 // we want to add to the lua debug count
1918 if (cbk->m_CallbackInfoRef != LUA_NOREF)
1919 {
1920 dmScript::Unref(L, LUA_REGISTRYINDEX, cbk->m_CallbackInfoRef);
1921 }
1922 lua_pop(L, 1);
1923
1924 cbk->m_Self = LUA_NOREF;
1925 cbk->m_Callback = LUA_NOREF;
1926 cbk->m_CallbackInfoRef = LUA_NOREF;
1927 cbk->m_ContextTableRef = LUA_NOREF;
1928 cbk->m_UniqueScriptId = INVALID_SCRIPT_ID;
1929 return;
1930 }
1931 else
1932 {
1933 dmLogWarning("Failed to unregister callback (it was not registered)");
1934 }
1935 }
1936
1937 bool SetupCallback(LuaCallbackInfo* cbk)
1938 {

Callers 15

LuaAnimationStoppedFunction · 0.85
Callback_AddMountFunction · 0.85
Resource_AddMountFunction · 0.85
FreeTimerFunction · 0.85
LuaTimerCallbackFunction · 0.85
TEST_FFunction · 0.85
DeleteRenderContextFunction · 0.85
RenderScript_SetListenerFunction · 0.85
LuaAnimationCompleteFunction · 0.85
PrewarmTextCallbackFunction · 0.85

Calls 5

lua_rawgetiFunction · 0.85
lua_typeFunction · 0.85
IsCallbackInstanceValidFunction · 0.85
luaL_unrefFunction · 0.85
UnrefFunction · 0.85

Tested by 1

TEST_FFunction · 0.68