Skip to content

Commit

Permalink
added support for UE5
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeioris committed Aug 22, 2021
1 parent bef5515 commit 9460e8f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
36 changes: 25 additions & 11 deletions Source/LuaMachine/Private/LuaBlueprintFunctionLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ UTexture2D* ULuaBlueprintFunctionLibrary::LuaValueToTransientTexture(int32 Width
return nullptr;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
TArray<uint8> UncompressedBytes;
#else
const TArray<uint8>* UncompressedBytes = nullptr;
Expand All @@ -547,7 +547,7 @@ UTexture2D* ULuaBlueprintFunctionLibrary::LuaValueToTransientTexture(int32 Width
PixelFormat = EPixelFormat::PF_B8G8R8A8;
Width = ImageWrapper->GetWidth();
Height = ImageWrapper->GetHeight();
#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
Bytes = UncompressedBytes;
#else
Bytes = *UncompressedBytes;
Expand Down Expand Up @@ -606,7 +606,7 @@ void ULuaBlueprintFunctionLibrary::LuaHttpRequest(UObject* WorldContextObject, T
if (!L)
return;

#if ENGINE_MINOR_VERSION >= 26
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 26
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest();
#else
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
Expand Down Expand Up @@ -675,7 +675,7 @@ void ULuaBlueprintFunctionLibrary::LuaRunURL(UObject* WorldContextObject, TSubcl
return;
}
}
#if ENGINE_MINOR_VERSION >= 26
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 26
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest();
#else
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
Expand Down Expand Up @@ -949,7 +949,7 @@ FLuaValue ULuaBlueprintFunctionLibrary::GetLuaComponentByStateAsLuaValue(AActor*
{
if (!Actor)
return FLuaValue();
#if ENGINE_MINOR_VERSION < 24
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION < 24
TArray<UActorComponent*> Components = Actor->GetComponentsByClass(ULuaComponent::StaticClass());
#else
TArray<UActorComponent*> Components;
Expand All @@ -975,7 +975,7 @@ FLuaValue ULuaBlueprintFunctionLibrary::GetLuaComponentByNameAsLuaValue(AActor*
if (!Actor)
return FLuaValue();

#if ENGINE_MINOR_VERSION < 24
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION < 24
TArray<UActorComponent*> Components = Actor->GetComponentsByClass(ULuaComponent::StaticClass());
#else
TArray<UActorComponent*> Components;
Expand Down Expand Up @@ -1820,7 +1820,11 @@ bool ULuaBlueprintFunctionLibrary::LuaLoadPakFile(const FString& Filename, FStri
bCustomPakPlatformFile = true;
}

#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26
TRefCountPtr<FPakFile> PakFile = new FPakFile(PakPlatformFile, *Filename, false);
#else
FPakFile PakFile(PakPlatformFile, *Filename, false);
#endif
if (!PakFile.IsValid())
{
UE_LOG(LogLuaMachine, Error, TEXT("Unable to open PakFile"));
Expand All @@ -1832,13 +1836,23 @@ bool ULuaBlueprintFunctionLibrary::LuaLoadPakFile(const FString& Filename, FStri
return false;
}

#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26
FString PakFileMountPoint = PakFile->GetMountPoint();
#else
FString PakFileMountPoint = PakFile.GetMountPoint();
#endif

FPaths::MakeStandardFilename(Mountpoint);

FString PakFileMountPoint(PakFile.GetMountPoint());
FPaths::MakeStandardFilename(PakFileMountPoint);

#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26
PakFile->SetMountPoint(*PakFileMountPoint);
#else
PakFile.SetMountPoint(*PakFileMountPoint);
#endif

if (!PakPlatformFile->Mount(*Filename, 0, *PakFile.GetMountPoint()))
if (!PakPlatformFile->Mount(*Filename, 0, *PakFileMountPoint))
{
UE_LOG(LogLuaMachine, Error, TEXT("Unable to mount PakFile"));
if (bCustomPakPlatformFile)
Expand All @@ -1854,15 +1868,15 @@ bool ULuaBlueprintFunctionLibrary::LuaLoadPakFile(const FString& Filename, FStri
ContentPath = "/Plugins" + Mountpoint + "Content/";
}

FString MountDestination = PakFile.GetMountPoint() + ContentPath;
FString MountDestination = PakFileMountPoint + ContentPath;
FPaths::MakeStandardFilename(MountDestination);

FPackageName::RegisterMountPoint(Mountpoint, MountDestination);

IAssetRegistry& AssetRegistry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")).Get();

#if WITH_EDITOR
#if ENGINE_MINOR_VERSION > 23
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 23
int32 bPreviousGAllowUnversionedContentInEditor = GAllowUnversionedContentInEditor;
#else
bool bPreviousGAllowUnversionedContentInEditor = GAllowUnversionedContentInEditor;
Expand All @@ -1876,7 +1890,7 @@ bool ULuaBlueprintFunctionLibrary::LuaLoadPakFile(const FString& Filename, FStri
}

FArrayReader SerializedAssetData;
if (!FFileHelper::LoadFileToArray(SerializedAssetData, *(PakFile.GetMountPoint() + AssetRegistryPath)))
if (!FFileHelper::LoadFileToArray(SerializedAssetData, *(PakFileMountPoint + AssetRegistryPath)))
{
UE_LOG(LogLuaMachine, Error, TEXT("Unable to parse AssetRegistry file"));
if (bCustomPakPlatformFile)
Expand Down
52 changes: 26 additions & 26 deletions Source/LuaMachine/Private/LuaState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ ULuaState::~ULuaState()
}
#endif

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FLuaValue ULuaState::FromUProperty(void* Buffer, FProperty * Property, bool& bSuccess, int32 Index)
{
return FromFProperty(Buffer, Property, bSuccess, Index);
Expand All @@ -1964,7 +1964,7 @@ void ULuaState::ToUProperty(void* Buffer, FProperty * Property, FLuaValue Value,
}
#endif

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FLuaValue ULuaState::FromFProperty(void* Buffer, FProperty * Property, bool& bSuccess, int32 Index)
#else
FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSuccess, int32 Index)
Expand All @@ -1988,7 +1988,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
LUAVALUE_PROP_CAST(ClassProperty, UObject*);
LUAVALUE_PROP_CAST(ObjectProperty, UObject*);

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FEnumProperty* EnumProperty = CastField<FEnumProperty>(Property);

if (EnumProperty)
Expand All @@ -1998,7 +1998,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
}
#endif

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FObjectPropertyBase* ObjectPropertyBase = CastField<FObjectPropertyBase>(Property);
#else
UObjectPropertyBase* ObjectPropertyBase = Cast<UObjectPropertyBase>(Property);
Expand All @@ -2008,7 +2008,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
return FLuaValue(ObjectPropertyBase->GetObjectPropertyValue_InContainer(Buffer, Index));
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FWeakObjectProperty* WeakObjectProperty = CastField<FWeakObjectProperty>(Property);
#else
UWeakObjectProperty* WeakObjectProperty = Cast<UWeakObjectProperty>(Property);
Expand All @@ -2019,7 +2019,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
return FLuaValue(WeakPtr.Get());
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FMulticastDelegateProperty* MulticastProperty = CastField<FMulticastDelegateProperty>(Property))
#else
if (UMulticastDelegateProperty* MulticastProperty = Cast<UMulticastDelegateProperty>(Property))
Expand All @@ -2030,7 +2030,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
return CreateLuaTable();
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FDelegateProperty* DelegateProperty = CastField<FDelegateProperty>(Property))
#else
if (UDelegateProperty* DelegateProperty = Cast<UDelegateProperty>(Property))
Expand All @@ -2040,7 +2040,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
return FLuaValue::FunctionOfObject((UObject*)ScriptDelegate.GetUObject(), ScriptDelegate.GetFunctionName());
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FArrayProperty* ArrayProperty = CastField<FArrayProperty>(Property))
#else
if (UArrayProperty* ArrayProperty = Cast<UArrayProperty>(Property))
Expand All @@ -2057,7 +2057,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
return NewLuaArray;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FMapProperty* MapProperty = CastField<FMapProperty>(Property))
#else
if (UMapProperty* MapProperty = Cast<UMapProperty>(Property))
Expand All @@ -2077,7 +2077,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
return NewLuaTable;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FSetProperty* SetProperty = CastField<FSetProperty>(Property))
#else
if (USetProperty* SetProperty = Cast<USetProperty>(Property))
Expand All @@ -2094,7 +2094,7 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
return NewLuaArray;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FStructProperty* StructProperty = CastField<FStructProperty>(Property))
#else
if (UStructProperty* StructProperty = Cast<UStructProperty>(Property))
Expand Down Expand Up @@ -2122,13 +2122,13 @@ FLuaValue ULuaState::FromUProperty(void* Buffer, UProperty * Property, bool& bSu
FLuaValue ULuaState::StructToLuaTable(UScriptStruct * InScriptStruct, const uint8 * StructData)
{
FLuaValue NewLuaTable = CreateLuaTable();
#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
for (TFieldIterator<FProperty> It(InScriptStruct); It; ++It)
#else
for (TFieldIterator<UProperty> It(InScriptStruct); It; ++It)
#endif
{
#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FProperty* FieldProp = *It;
#else
UProperty* FieldProp = *It;
Expand All @@ -2145,7 +2145,7 @@ FLuaValue ULuaState::StructToLuaTable(UScriptStruct * InScriptStruct, const TArr
return StructToLuaTable(InScriptStruct, StructData.GetData());
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
void ULuaState::ToFProperty(void* Buffer, FProperty * Property, FLuaValue Value, bool& bSuccess, int32 Index)
#else
void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value, bool& bSuccess, int32 Index)
Expand All @@ -2169,7 +2169,7 @@ void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value,
LUAVALUE_PROP_SET(ClassProperty, Value.Object);
LUAVALUE_PROP_SET(ObjectProperty, Value.Object);

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FObjectPropertyBase* ObjectPropertyBase = CastField<FObjectPropertyBase>(Property);
#else
UObjectPropertyBase* ObjectPropertyBase = Cast<UObjectPropertyBase>(Property);
Expand All @@ -2179,7 +2179,7 @@ void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value,
ObjectPropertyBase->SetObjectPropertyValue_InContainer(Buffer, Value.Object, Index);
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FWeakObjectProperty* WeakObjectProperty = CastField<FWeakObjectProperty>(Property);
#else
UWeakObjectProperty* WeakObjectProperty = Cast<UWeakObjectProperty>(Property);
Expand All @@ -2191,7 +2191,7 @@ void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value,
return;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FMulticastDelegateProperty* MulticastProperty = CastField<FMulticastDelegateProperty>(Property))
#else
if (UMulticastDelegateProperty* MulticastProperty = Cast<UMulticastDelegateProperty>(Property))
Expand All @@ -2208,7 +2208,7 @@ void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value,
return;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FDelegateProperty* DelegateProperty = CastField<FDelegateProperty>(Property))
#else
if (UDelegateProperty* DelegateProperty = Cast<UDelegateProperty>(Property))
Expand All @@ -2225,7 +2225,7 @@ void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value,
return;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FStructProperty* StructProperty = CastField<FStructProperty>(Property))
#else
if (UStructProperty* StructProperty = Cast<UStructProperty>(Property))
Expand All @@ -2244,7 +2244,7 @@ void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value,
return;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FArrayProperty* ArrayProperty = CastField<FArrayProperty>(Property))
#else
if (UArrayProperty* ArrayProperty = Cast<UArrayProperty>(Property))
Expand All @@ -2262,7 +2262,7 @@ void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value,
return;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FMapProperty* MapProperty = CastField<FMapProperty>(Property))
#else
if (UMapProperty* MapProperty = Cast<UMapProperty>(Property))
Expand All @@ -2284,7 +2284,7 @@ void ULuaState::ToUProperty(void* Buffer, UProperty * Property, FLuaValue Value,
return;
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
if (FSetProperty* SetProperty = CastField<FSetProperty>(Property))
#else
if (USetProperty* SetProperty = Cast<USetProperty>(Property))
Expand All @@ -2310,7 +2310,7 @@ void ULuaState::LuaTableToStruct(FLuaValue & LuaValue, UScriptStruct * InScriptS
TArray<FLuaValue> TableKeys = ULuaBlueprintFunctionLibrary::LuaTableGetKeys(LuaValue);
for (FLuaValue TableKey : TableKeys)
{
#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FProperty* StructProp = InScriptStruct->FindPropertyByName(TableKey.ToName());
#else
UProperty* StructProp = InScriptStruct->FindPropertyByName(TableKey.ToName());
Expand All @@ -2323,7 +2323,7 @@ void ULuaState::LuaTableToStruct(FLuaValue & LuaValue, UScriptStruct * InScriptS
}
}

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
void ULuaState::ToProperty(void* Buffer, FProperty * Property, FLuaValue Value, bool& bSuccess, int32 Index)
{
ToFProperty(Buffer, Property, Value, bSuccess, Index);
Expand Down Expand Up @@ -2353,7 +2353,7 @@ FLuaValue ULuaState::GetLuaValueFromProperty(UObject * InObject, const FString &
}

UClass* Class = InObject->GetClass();
#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FProperty* Property = nullptr;
#else
UProperty* Property = nullptr;
Expand All @@ -2376,7 +2376,7 @@ bool ULuaState::SetPropertyFromLuaValue(UObject * InObject, const FString & Prop
}

UClass* Class = InObject->GetClass();
#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FProperty* Property = nullptr;
#else
UProperty* Property = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Source/LuaMachine/Public/LuaState.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class LUAMACHINE_API ULuaState : public UObject
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Lua")
static TArray<uint8> ToByteCode(const FString& Code, const FString& CodePath, FString& ErrorString);

#if ENGINE_MINOR_VERSION >= 25
#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION >= 25
FLuaValue FromUProperty(void* Buffer, FProperty* Property, bool& bSuccess, int32 Index = 0);
void ToUProperty(void* Buffer, FProperty* Property, FLuaValue Value, bool& bSuccess, int32 Index = 0);
FLuaValue FromFProperty(void* Buffer, FProperty* Property, bool& bSuccess, int32 Index = 0);
Expand Down

0 comments on commit 9460e8f

Please sign in to comment.