| 65 | } |
| 66 | |
| 67 | bool ULuaFunction::Override(UFunction* Function, UClass* Outer, FName NewName) |
| 68 | { |
| 69 | ULuaFunction* LuaFunction; |
| 70 | const auto bReplace = Function->GetOuter() == Outer; |
| 71 | if (bReplace) |
| 72 | { |
| 73 | // ReplaceFunction |
| 74 | LuaFunction = Cast<ULuaFunction>(Function); |
| 75 | if (LuaFunction) |
| 76 | { |
| 77 | LuaFunction->Initialize(); |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | const auto OverriddenName = FString::Printf(TEXT("%s%s"), *Function->GetName(), OverriddenSuffix.Get()); |
| 82 | Function->Rename(*OverriddenName, nullptr, RenameFlags); |
| 83 | Outer->AddFunctionToFunctionMap(Function, Function->GetFName()); |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | // AddFunction |
| 88 | if (Outer->FindFunctionByName(NewName, EIncludeSuperFlag::ExcludeSuper)) |
| 89 | return false; |
| 90 | |
| 91 | if (Function->HasAnyFunctionFlags(FUNC_Native)) |
| 92 | { |
| 93 | // Need to do this before the call to DuplicateObject in the case that the super-function already has FUNC_Native |
| 94 | Outer->AddNativeFunction(*NewName.ToString(), &execCallLua); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | FObjectDuplicationParameters DuplicationParams(Function, Outer); |
| 99 | DuplicationParams.InternalFlagMask &= ~EInternalObjectFlags::Native; |
| 100 | DuplicationParams.DestName = NewName; |
| 101 | DuplicationParams.DestClass = StaticClass(); |
| 102 | LuaFunction = static_cast<ULuaFunction*>(StaticDuplicateObjectEx(DuplicationParams)); |
| 103 | LuaFunction->FunctionFlags |= FUNC_Native; |
| 104 | LuaFunction->Overridden = Function->IsA<ULuaFunction>() ? static_cast<ULuaFunction*>(Function)->GetOverridden() : Function; |
| 105 | LuaFunction->ClearInternalFlags(EInternalObjectFlags::Native); |
| 106 | LuaFunction->SetNativeFunc(execCallLua); |
| 107 | |
| 108 | if (bReplace) |
| 109 | LuaFunction->SetSuperStruct(Function->GetSuperStruct()); |
| 110 | else |
| 111 | LuaFunction->SetSuperStruct(Function); |
| 112 | |
| 113 | #if WITH_EDITOR |
| 114 | UMetaData::CopyMetadata(Function, LuaFunction); |
| 115 | Function->RemoveMetaData(NAME_CallInEditor); |
| 116 | #endif |
| 117 | |
| 118 | LuaFunction->StaticLink(true); |
| 119 | LuaFunction->Initialize(); |
| 120 | |
| 121 | Outer->AddFunctionToFunctionMap(LuaFunction, NewName); |
| 122 | |
| 123 | LuaFunction->Next = Outer->Children; |
| 124 | Outer->Children = LuaFunction; |
nothing calls this directly
no test coverage detected