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

Method PreCall

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

* Prepare values of properties for the UFunction */

Source from the content-addressed store, hash-verified

392 * Prepare values of properties for the UFunction
393 */
394void* FFunctionDesc::PreCall(lua_State* L, int32 NumParams, int32 FirstParamIndex, FFlagArray& CleanupFlags, void* Userdata)
395{
396#if ENABLE_PERSISTENT_PARAM_BUFFER
397 void* Params = Buffer;
398#else
399 void* Params = Function->ParmsSize > 0 ? FMemory::Malloc(Function->ParmsSize, 16) : nullptr;
400#endif
401
402#if !SUPPORTS_RPC_CALL
403 ++NumCalls;
404#endif
405
406 int32 ParamIndex = 0;
407 for (int32 i = 0; i < Properties.Num(); ++i)
408 {
409 const auto& Property = Properties[i];
410 Property->InitializeValue(Params);
411 if (i == LatentPropertyIndex)
412 {
413 const int32 ThreadRef = *((int32*)Userdata);
414 void* ContainerPtr = (uint8*)Params;// + Property->GetOffset();
415 if(lua_type(L, FirstParamIndex + ParamIndex) == LUA_TUSERDATA)
416 {
417 // custom latent action info
418 FLatentActionInfo Info = UnLua::Get<FLatentActionInfo>(L, FirstParamIndex + ParamIndex, UnLua::TType<FLatentActionInfo>());
419 Property->CopyValue(ContainerPtr, &Info);
420 continue;
421 }
422
423 // bind a callback to the latent function
424 auto& Env = UnLua::FLuaEnv::FindEnvChecked(L);
425 FLatentActionInfo LatentActionInfo(ThreadRef, GetTypeHash(FGuid::NewGuid()), TEXT("OnLatentActionCompleted"), (Env.GetManager()));
426 Property->CopyValue(ContainerPtr, &LatentActionInfo);
427 continue;
428 }
429 if (i == ReturnPropertyIndex)
430 {
431 CleanupFlags[i] = ParamIndex >= NumParams || !Property->CopyBack(L, FirstParamIndex + ParamIndex, Params);
432 continue;
433 }
434 if (ParamIndex < NumParams)
435 {
436#if ENABLE_TYPE_CHECK == 1
437 FString ErrorMsg = "";
438 if (!Property->CheckPropertyType(L, FirstParamIndex + ParamIndex, ErrorMsg))
439 {
440 UNLUA_LOGERROR(L, LogUnLua, Warning, TEXT("Invalid parameter type calling ufunction : %s,parameter : %d, error msg : %s"), *FuncName, ParamIndex, *ErrorMsg);
441 }
442#endif
443 CleanupFlags[i] = Property->SetValue(L, Params, FirstParamIndex + ParamIndex, false);
444 }
445 else if (!Property->IsOutParameter())
446 {
447 if (DefaultParams)
448 {
449 // set value for default parameter
450 IParamValue **DefaultValue = DefaultParams->Parameters.Find(Property->GetProperty()->GetFName());
451 if (DefaultValue)

Callers

nothing calls this directly

Calls 13

lua_typeFunction · 0.85
GetTypeHashFunction · 0.85
InitializeValueMethod · 0.80
CopyValueMethod · 0.80
GetManagerMethod · 0.80
IsOutParameterMethod · 0.80
NumMethod · 0.45
CopyBackMethod · 0.45
CheckPropertyTypeMethod · 0.45
SetValueMethod · 0.45
FindMethod · 0.45
GetPropertyMethod · 0.45

Tested by

no test coverage detected