MCPcopy Create free account
hub / github.com/Tencent/UnLua / PushFunction

Function PushFunction

Plugins/UnLua/Source/UnLua/Private/LuaCore.cpp:887–929  ·  view source on GitHub ↗

* Push a Lua function (by a function name) and push a UObject instance as its first parameter */

Source from the content-addressed store, hash-verified

885 * Push a Lua function (by a function name) and push a UObject instance as its first parameter
886 */
887int32 PushFunction(lua_State *L, UObjectBaseUtility *Object, const char *FunctionName)
888{
889 int32 N = lua_gettop(L);
890 lua_pushcfunction(L, UnLua::ReportLuaCallError);
891 const auto& Env = UnLua::FLuaEnv::FindEnv(L);
892 const auto Ref = Env->GetObjectRegistry()->GetBoundRef((UObject*)Object);
893 if (Ref != LUA_NOREF)
894 {
895 lua_rawgeti(L, LUA_REGISTRYINDEX, Ref);
896 int32 Type = lua_type(L, -1);
897 if (Type == LUA_TTABLE /*|| Type == LUA_TUSERDATA*/)
898 {
899 if (lua_getmetatable(L, -1) == 1)
900 {
901 do
902 {
903 lua_pushstring(L, FunctionName);
904 lua_rawget(L, -2);
905 if (lua_isfunction(L, -1))
906 {
907 lua_pushvalue(L, -3);
908 lua_remove(L, -3);
909 lua_remove(L, -3);
910 lua_pushvalue(L, -2);
911 return luaL_ref(L, LUA_REGISTRYINDEX);
912 }
913 else
914 {
915 lua_pop(L, 1);
916 lua_pushstring(L, "Super");
917 lua_rawget(L, -2);
918 lua_remove(L, -2);
919 }
920 } while (lua_istable(L, -1));
921 }
922 }
923 }
924 if (int32 NumToPop = lua_gettop(L) - N)
925 {
926 lua_pop(L, NumToPop);
927 }
928 return LUA_NOREF;
929}
930
931/**
932 * Push a Lua function (by a function reference) and push a UObject instance as its first parameter

Callers 2

BindMethod · 0.85
CallLuaMethod · 0.85

Calls 10

lua_gettopFunction · 0.85
lua_rawgetiFunction · 0.85
lua_typeFunction · 0.85
lua_getmetatableFunction · 0.85
lua_pushstringFunction · 0.85
lua_rawgetFunction · 0.85
lua_pushvalueFunction · 0.85
luaL_refFunction · 0.85
PushUObjectFunction · 0.85
GetBoundRefMethod · 0.45

Tested by

no test coverage detected