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

Method CallUE

Plugins/UnLua/Source/UnLua/Private/ReflectionUtils/FunctionDesc.cpp:247–356  ·  view source on GitHub ↗

* Call the UFunction */

Source from the content-addressed store, hash-verified

245 * Call the UFunction
246 */
247int32 FFunctionDesc::CallUE(lua_State *L, int32 NumParams, void *Userdata)
248{
249 check(Function.IsValid());
250
251 UObject* Object;
252 int32 FirstParamIndex;
253 if (bStaticFunc)
254 {
255 Object = Function->GetOuterUClass()->GetDefaultObject(); // get CDO for static function
256 FirstParamIndex = 1;
257 }
258 else if (NumParams > 0)
259 {
260 Object = UnLua::GetUObject(L, 1, false);
261 FirstParamIndex = 2;
262 --NumParams;
263 }
264 else
265 {
266 Object = nullptr;
267 FirstParamIndex = 1;
268 }
269
270 if (Object == UnLua::LowLevel::ReleasedPtr)
271 return luaL_error(L, "attempt to call UFunction '%s' on released object.", TCHAR_TO_UTF8(*FuncName));
272
273 if (Object == nullptr)
274 return luaL_error(L, "attempt to call UFunction '%s' on NULL object. (check the usage of ':' and '.')", TCHAR_TO_UTF8(*FuncName));
275
276 if (Object->IsUnreachable())
277 return luaL_error(L, "attempt to call UFunction '%s' on Unreachable object '%s'.", TCHAR_TO_UTF8(*FuncName), TCHAR_TO_UTF8(*Object->GetName()));
278
279#if SUPPORTS_RPC_CALL
280 int32 Callspace = Object->GetFunctionCallspace(Function.Get(), nullptr);
281 bool bRemote = Callspace & FunctionCallspace::Remote;
282 bool bLocal = Callspace & FunctionCallspace::Local;
283#else
284 bool bRemote = false;
285 bool bLocal = true;
286#endif
287
288 FFlagArray CleanupFlags;
289 void *Params = PreCall(L, NumParams, FirstParamIndex, CleanupFlags, Userdata); // prepare values of properties
290
291 UFunction *FinalFunction = Function.Get();
292 if (bInterfaceFunc)
293 {
294 // get target UFunction if it's a function in Interface
295 FName FunctionName = Function->GetFName();
296 FinalFunction = Object->GetClass()->FindFunctionByName(FunctionName);
297 if (!FinalFunction)
298 {
299 UNLUA_LOGERROR(L, LogUnLua, Error, TEXT("ERROR! Can't find UFunction '%s' in target object!"), *FuncName);
300
301#if !ENABLE_PERSISTENT_PARAM_BUFFER
302 if (Params)
303 FMemory::Free(Params);
304#endif

Callers 2

Class_CallUFunctionFunction · 0.80
Class_CallLatentFunctionFunction · 0.80

Calls 8

checkFunction · 0.85
GetUObjectFunction · 0.85
luaL_errorFunction · 0.85
GetOverriddenMethod · 0.80
IsValidMethod · 0.45
GetNameMethod · 0.45
GetMethod · 0.45
InvokeMethod · 0.45

Tested by

no test coverage detected