* Push a Lua function (by a function name) and push a UObject instance as its first parameter */
| 885 | * Push a Lua function (by a function name) and push a UObject instance as its first parameter |
| 886 | */ |
| 887 | int32 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 |
no test coverage detected