chore: initialize UE 5.8 + UnLua game framework project
This commit is contained in:
commit
943af16954
397 files changed
+95588
No files matched your search
@@ -0,0 +1,15 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class UnrealLuaDemoTarget : TargetRules
|
||||
{
|
||||
public UnrealLuaDemoTarget(TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Game;
|
||||
DefaultBuildSettings = BuildSettingsVersion.V7;
|
||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_8;
|
||||
ExtraModuleNames.Add("UnrealLuaDemo");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "Core/LuaBlueprintLibrary.h"
|
||||
#include "HotUpdate/LuaHotUpdateSubsystem.h"
|
||||
|
||||
FString ULuaBlueprintLibrary::GetHotUpdateScriptDir()
|
||||
{
|
||||
return ULuaHotUpdateSubsystem::GetHotUpdateScriptDir();
|
||||
}
|
||||
|
||||
FString ULuaBlueprintLibrary::GetDefaultScriptDir()
|
||||
{
|
||||
return ULuaHotUpdateSubsystem::GetDefaultScriptDir();
|
||||
}
|
||||
|
||||
void ULuaBlueprintLibrary::TriggerLuaHotReload()
|
||||
{
|
||||
ULuaHotUpdateSubsystem::ReloadAllLuaModules();
|
||||
}
|
||||
|
||||
bool ULuaBlueprintLibrary::ReloadLuaModule(const FString& ModuleName)
|
||||
{
|
||||
return ULuaHotUpdateSubsystem::ReloadLuaModule(ModuleName);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "LuaBlueprintLibrary.generated.h"
|
||||
|
||||
/**
|
||||
* Blueprint & Lua callable utility functions for the game framework.
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMO_API ULuaBlueprintLibrary : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintPure, Category = "Lua|Framework")
|
||||
static FString GetHotUpdateScriptDir();
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Lua|Framework")
|
||||
static FString GetDefaultScriptDir();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Lua|Framework")
|
||||
static void TriggerLuaHotReload();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Lua|Framework")
|
||||
static bool ReloadLuaModule(const FString& ModuleName);
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "Core/LuaCharacter.h"
|
||||
|
||||
ALuaCharacter::ALuaCharacter()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
}
|
||||
|
||||
FString ALuaCharacter::GetModuleName_Implementation() const
|
||||
{
|
||||
return LuaModuleName;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "UnLuaInterface.h"
|
||||
#include "LuaCharacter.generated.h"
|
||||
|
||||
/**
|
||||
* Base Character bound to Lua (Content/Script/Game/LuaCharacter.lua).
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMO_API ALuaCharacter : public ACharacter, public IUnLuaInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ALuaCharacter();
|
||||
|
||||
virtual FString GetModuleName_Implementation() const override;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Lua")
|
||||
FString LuaModuleName = TEXT("Game.LuaCharacter");
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "Core/LuaGameInstance.h"
|
||||
#include "UnrealLuaDemo.h"
|
||||
|
||||
void ULuaGameInstance::Init()
|
||||
{
|
||||
Super::Init();
|
||||
UE_LOG(LogUnrealLuaDemo, Log, TEXT("ULuaGameInstance::Init() - LuaModule=%s"), *LuaModuleName);
|
||||
}
|
||||
|
||||
void ULuaGameInstance::Shutdown()
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemo, Log, TEXT("ULuaGameInstance::Shutdown()"));
|
||||
Super::Shutdown();
|
||||
}
|
||||
|
||||
FString ULuaGameInstance::GetModuleName_Implementation() const
|
||||
{
|
||||
return LuaModuleName;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Engine/GameInstance.h"
|
||||
#include "UnLuaInterface.h"
|
||||
#include "LuaGameInstance.generated.h"
|
||||
|
||||
/**
|
||||
* Base GameInstance bound to Lua (Content/Script/Game/LuaGameInstance.lua).
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMO_API ULuaGameInstance : public UGameInstance, public IUnLuaInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void Init() override;
|
||||
virtual void Shutdown() override;
|
||||
|
||||
virtual FString GetModuleName_Implementation() const override;
|
||||
|
||||
protected:
|
||||
/** Lua module name bound to this GameInstance (relative to Content/Script). */
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Lua")
|
||||
FString LuaModuleName = TEXT("Game.LuaGameInstance");
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "Core/LuaGameModeBase.h"
|
||||
#include "Core/LuaPlayerController.h"
|
||||
#include "Core/LuaCharacter.h"
|
||||
|
||||
ALuaGameModeBase::ALuaGameModeBase()
|
||||
{
|
||||
PlayerControllerClass = ALuaPlayerController::StaticClass();
|
||||
DefaultPawnClass = ALuaCharacter::StaticClass();
|
||||
}
|
||||
|
||||
FString ALuaGameModeBase::GetModuleName_Implementation() const
|
||||
{
|
||||
return LuaModuleName;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "UnLuaInterface.h"
|
||||
#include "LuaGameModeBase.generated.h"
|
||||
|
||||
/**
|
||||
* Base GameMode bound to Lua (Content/Script/Game/LuaGameMode.lua).
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMO_API ALuaGameModeBase : public AGameModeBase, public IUnLuaInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ALuaGameModeBase();
|
||||
|
||||
virtual FString GetModuleName_Implementation() const override;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Lua")
|
||||
FString LuaModuleName = TEXT("Game.LuaGameMode");
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "Core/LuaPlayerController.h"
|
||||
|
||||
FString ALuaPlayerController::GetModuleName_Implementation() const
|
||||
{
|
||||
return LuaModuleName;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "UnLuaInterface.h"
|
||||
#include "LuaPlayerController.generated.h"
|
||||
|
||||
/**
|
||||
* Base PlayerController bound to Lua (Content/Script/Game/LuaPlayerController.lua).
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMO_API ALuaPlayerController : public APlayerController, public IUnLuaInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual FString GetModuleName_Implementation() const override;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Lua")
|
||||
FString LuaModuleName = TEXT("Game.LuaPlayerController");
|
||||
};
|
||||
@@ -0,0 +1,186 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "HotUpdate/LuaHotUpdateSubsystem.h"
|
||||
#include "UnrealLuaDemo.h"
|
||||
#include "UnLuaDelegates.h"
|
||||
#include "HAL/FileManager.h"
|
||||
#include "Misc/FileHelper.h"
|
||||
#include "Misc/Paths.h"
|
||||
|
||||
void ULuaHotUpdateSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||
{
|
||||
Super::Initialize(Collection);
|
||||
|
||||
// Ensure hot-update script directory exists for easy testing/patching
|
||||
const FString HotUpdateDir = GetHotUpdateScriptDir();
|
||||
if (!IFileManager::Get().DirectoryExists(*HotUpdateDir))
|
||||
{
|
||||
IFileManager::Get().MakeDirectory(*HotUpdateDir, true);
|
||||
}
|
||||
|
||||
UE_LOG(LogUnrealLuaDemo, Log, TEXT("LuaHotUpdateSubsystem initialized. OverrideDir=%s DefaultDir=%s"),
|
||||
*HotUpdateDir, *GetDefaultScriptDir());
|
||||
}
|
||||
|
||||
void ULuaHotUpdateSubsystem::Deinitialize()
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemo, Log, TEXT("LuaHotUpdateSubsystem deinitialized."));
|
||||
Super::Deinitialize();
|
||||
}
|
||||
|
||||
void ULuaHotUpdateSubsystem::RegisterHotUpdateLoader()
|
||||
{
|
||||
FUnLuaDelegates::CustomLoadLuaFile.BindStatic(&ULuaHotUpdateSubsystem::HandleCustomLoadLuaFile);
|
||||
}
|
||||
|
||||
void ULuaHotUpdateSubsystem::UnregisterHotUpdateLoader()
|
||||
{
|
||||
FUnLuaDelegates::CustomLoadLuaFile.Unbind();
|
||||
}
|
||||
|
||||
FString ULuaHotUpdateSubsystem::GetHotUpdateScriptDir()
|
||||
{
|
||||
#if PLATFORM_IOS || PLATFORM_ANDROID
|
||||
return FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::ProjectPersistentDownloadDir(), TEXT("HotUpdate/Script")));
|
||||
#else
|
||||
return FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::ProjectSavedDir(), TEXT("HotUpdate/Script")));
|
||||
#endif
|
||||
}
|
||||
|
||||
FString ULuaHotUpdateSubsystem::GetDefaultScriptDir()
|
||||
{
|
||||
return FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::ProjectContentDir(), TEXT("Script")));
|
||||
}
|
||||
|
||||
void ULuaHotUpdateSubsystem::ReloadAllLuaModules()
|
||||
{
|
||||
TMap<lua_State*, UnLua::FLuaEnv*>& AllEnvs = UnLua::FLuaEnv::GetAll();
|
||||
if (AllEnvs.Num() == 0)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemo, Warning, TEXT("ReloadAllLuaModules: No active Lua environment."));
|
||||
return;
|
||||
}
|
||||
|
||||
for (const TPair<lua_State*, UnLua::FLuaEnv*>& Pair : AllEnvs)
|
||||
{
|
||||
if (UnLua::FLuaEnv* Env = Pair.Value)
|
||||
{
|
||||
Env->DoString(TEXT("require('Framework.HotReload').ReloadAll()"), TEXT("HotReloadAll"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ULuaHotUpdateSubsystem::ReloadLuaModule(const FString& ModuleName)
|
||||
{
|
||||
if (ModuleName.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemo, Warning, TEXT("ReloadLuaModule: ModuleName is empty."));
|
||||
return false;
|
||||
}
|
||||
|
||||
TMap<lua_State*, UnLua::FLuaEnv*>& AllEnvs = UnLua::FLuaEnv::GetAll();
|
||||
if (AllEnvs.Num() == 0)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemo, Warning, TEXT("ReloadLuaModule(%s): No active Lua environment."), *ModuleName);
|
||||
return false;
|
||||
}
|
||||
|
||||
FString EscapedName = ModuleName;
|
||||
EscapedName.ReplaceInline(TEXT("\\"), TEXT("\\\\"));
|
||||
EscapedName.ReplaceInline(TEXT("'"), TEXT("\\'"));
|
||||
|
||||
const FString Chunk = FString::Printf(TEXT("require('Framework.HotReload').ReloadModule('%s')"), *EscapedName);
|
||||
bool bAnySucceeded = false;
|
||||
|
||||
for (const TPair<lua_State*, UnLua::FLuaEnv*>& Pair : AllEnvs)
|
||||
{
|
||||
if (UnLua::FLuaEnv* Env = Pair.Value)
|
||||
{
|
||||
if (Env->DoString(Chunk, TEXT("HotReloadModule")))
|
||||
{
|
||||
bAnySucceeded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bAnySucceeded;
|
||||
}
|
||||
|
||||
bool ULuaHotUpdateSubsystem::ExecuteLuaString(const FString& LuaCode)
|
||||
{
|
||||
if (LuaCode.IsEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TMap<lua_State*, UnLua::FLuaEnv*>& AllEnvs = UnLua::FLuaEnv::GetAll();
|
||||
bool bAnySucceeded = false;
|
||||
|
||||
for (const TPair<lua_State*, UnLua::FLuaEnv*>& Pair : AllEnvs)
|
||||
{
|
||||
if (UnLua::FLuaEnv* Env = Pair.Value)
|
||||
{
|
||||
if (Env->DoString(LuaCode, TEXT("ExecuteLuaString")))
|
||||
{
|
||||
bAnySucceeded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bAnySucceeded;
|
||||
}
|
||||
|
||||
bool ULuaHotUpdateSubsystem::TryLoadLuaFromRoot(
|
||||
const FString& RootDir,
|
||||
const FString& NormalizedModulePath,
|
||||
TArray<uint8>& OutData,
|
||||
FString& OutFullPath)
|
||||
{
|
||||
// Try <Root>/<ModulePath>.lua first, then <Root>/<ModulePath>/init.lua
|
||||
const FString DirectPath = FPaths::Combine(RootDir, NormalizedModulePath + TEXT(".lua"));
|
||||
if (FPaths::FileExists(DirectPath) && FFileHelper::LoadFileToArray(OutData, *DirectPath, FILEREAD_Silent))
|
||||
{
|
||||
OutFullPath = DirectPath;
|
||||
return true;
|
||||
}
|
||||
|
||||
const FString InitPath = FPaths::Combine(RootDir, NormalizedModulePath, TEXT("init.lua"));
|
||||
if (FPaths::FileExists(InitPath) && FFileHelper::LoadFileToArray(OutData, *InitPath, FILEREAD_Silent))
|
||||
{
|
||||
OutFullPath = InitPath;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ULuaHotUpdateSubsystem::HandleCustomLoadLuaFile(
|
||||
UnLua::FLuaEnv& Env,
|
||||
const FString& RelativeFilePath,
|
||||
TArray<uint8>& Data,
|
||||
FString& FullFilePath)
|
||||
{
|
||||
FString Normalized = RelativeFilePath;
|
||||
if (Normalized.EndsWith(TEXT(".lua"), ESearchCase::IgnoreCase))
|
||||
{
|
||||
Normalized.LeftChopInline(4);
|
||||
}
|
||||
Normalized.ReplaceInline(TEXT("."), TEXT("/"));
|
||||
Normalized.ReplaceInline(TEXT("\\"), TEXT("/"));
|
||||
|
||||
// 1. Prioritize hot-update override directory
|
||||
if (TryLoadLuaFromRoot(GetHotUpdateScriptDir(), Normalized, Data, FullFilePath))
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemo, Verbose, TEXT("[HotUpdate] Loaded Lua module '%s' from override: %s"), *RelativeFilePath, *FullFilePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. Fallback to project Content/Script directory
|
||||
if (TryLoadLuaFromRoot(GetDefaultScriptDir(), Normalized, Data, FullFilePath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Return false to fall through to UnLua's default loaders (e.g. Plugins/UnLua/Content/Script)
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Subsystems/GameInstanceSubsystem.h"
|
||||
#include "LuaEnv.h"
|
||||
#include "LuaHotUpdateSubsystem.generated.h"
|
||||
|
||||
/**
|
||||
* Manages Lua script hot-update resolution and runtime hot-reloading.
|
||||
*
|
||||
* Script search priority:
|
||||
* 1. Hot-update override directory: <Saved>/HotUpdate/Script/ (or PersistentDownloadDir on mobile)
|
||||
* 2. Default project script directory: <Content>/Script/
|
||||
* 3. Falls through to UnLua's default filesystem/plugin loaders (e.g. Plugins/UnLua/Content/Script/)
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMO_API ULuaHotUpdateSubsystem : public UGameInstanceSubsystem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
virtual void Deinitialize() override;
|
||||
|
||||
/** Registers the global custom Lua loader with UnLua. */
|
||||
static void RegisterHotUpdateLoader();
|
||||
|
||||
/** Unregisters the global custom Lua loader from UnLua. */
|
||||
static void UnregisterHotUpdateLoader();
|
||||
|
||||
/** Returns the writable directory where hot-updated Lua scripts are placed. */
|
||||
UFUNCTION(BlueprintPure, Category = "Lua|HotUpdate")
|
||||
static FString GetHotUpdateScriptDir();
|
||||
|
||||
/** Returns the default packaged/project Lua script directory (Content/Script). */
|
||||
UFUNCTION(BlueprintPure, Category = "Lua|HotUpdate")
|
||||
static FString GetDefaultScriptDir();
|
||||
|
||||
/** Triggers UnLua hot-reload across all active Lua environments. */
|
||||
UFUNCTION(BlueprintCallable, Category = "Lua|HotUpdate")
|
||||
static void ReloadAllLuaModules();
|
||||
|
||||
/** Hot-reloads a single dot-separated Lua module (e.g. "Game.LuaGameMode"). */
|
||||
UFUNCTION(BlueprintCallable, Category = "Lua|HotUpdate")
|
||||
static bool ReloadLuaModule(const FString& ModuleName);
|
||||
|
||||
/** Executes an arbitrary Lua code chunk in all active Lua environments. */
|
||||
UFUNCTION(BlueprintCallable, Category = "Lua|HotUpdate")
|
||||
static bool ExecuteLuaString(const FString& LuaCode);
|
||||
|
||||
private:
|
||||
static bool HandleCustomLoadLuaFile(UnLua::FLuaEnv& Env, const FString& RelativeFilePath, TArray<uint8>& Data, FString& FullFilePath);
|
||||
static bool TryLoadLuaFromRoot(const FString& RootDir, const FString& NormalizedModulePath, TArray<uint8>& OutData, FString& OutFullPath);
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class UnrealLuaDemo : ModuleRules
|
||||
{
|
||||
public UnrealLuaDemo(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicIncludePaths.Add(ModuleDirectory);
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[]
|
||||
{
|
||||
"Core",
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
"InputCore",
|
||||
"EnhancedInput",
|
||||
"UMG",
|
||||
"UnLua",
|
||||
"Lua"
|
||||
});
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[]
|
||||
{
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
"Json",
|
||||
"JsonUtilities",
|
||||
"HTTP"
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "UnrealLuaDemo.h"
|
||||
#include "HotUpdate/LuaHotUpdateSubsystem.h"
|
||||
#include "HAL/IConsoleManager.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogUnrealLuaDemo);
|
||||
|
||||
void FUnrealLuaDemoModule::StartupModule()
|
||||
{
|
||||
FDefaultGameModuleImpl::StartupModule();
|
||||
|
||||
ULuaHotUpdateSubsystem::RegisterHotUpdateLoader();
|
||||
|
||||
HotReloadCmd = IConsoleManager::Get().RegisterConsoleCommand(
|
||||
TEXT("Lua.HotReload"),
|
||||
TEXT("Trigger UnLua full hot-reload across all active Lua environments."),
|
||||
FConsoleCommandDelegate::CreateStatic(&ULuaHotUpdateSubsystem::ReloadAllLuaModules),
|
||||
ECVF_Default);
|
||||
|
||||
ReloadModuleCmd = IConsoleManager::Get().RegisterConsoleCommand(
|
||||
TEXT("Lua.ReloadModule"),
|
||||
TEXT("Hot-reload a specific Lua module. Usage: Lua.ReloadModule <ModuleName>"),
|
||||
FConsoleCommandWithArgsDelegate::CreateLambda([](const TArray<FString>& Args)
|
||||
{
|
||||
if (Args.Num() > 0)
|
||||
{
|
||||
ULuaHotUpdateSubsystem::ReloadLuaModule(Args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemo, Warning, TEXT("Usage: Lua.ReloadModule <ModuleName>"));
|
||||
}
|
||||
}),
|
||||
ECVF_Default);
|
||||
|
||||
UE_LOG(LogUnrealLuaDemo, Log, TEXT("UnrealLuaDemo module started. Hot-update script dir: %s"),
|
||||
*ULuaHotUpdateSubsystem::GetHotUpdateScriptDir());
|
||||
}
|
||||
|
||||
void FUnrealLuaDemoModule::ShutdownModule()
|
||||
{
|
||||
if (HotReloadCmd)
|
||||
{
|
||||
IConsoleManager::Get().UnregisterConsoleObject(HotReloadCmd);
|
||||
HotReloadCmd = nullptr;
|
||||
}
|
||||
|
||||
if (ReloadModuleCmd)
|
||||
{
|
||||
IConsoleManager::Get().UnregisterConsoleObject(ReloadModuleCmd);
|
||||
ReloadModuleCmd = nullptr;
|
||||
}
|
||||
|
||||
ULuaHotUpdateSubsystem::UnregisterHotUpdateLoader();
|
||||
|
||||
FDefaultGameModuleImpl::ShutdownModule();
|
||||
}
|
||||
|
||||
IMPLEMENT_PRIMARY_GAME_MODULE(FUnrealLuaDemoModule, UnrealLuaDemo, "UnrealLuaDemo");
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogUnrealLuaDemo, Log, All);
|
||||
|
||||
class FUnrealLuaDemoModule : public FDefaultGameModuleImpl
|
||||
{
|
||||
public:
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
|
||||
private:
|
||||
IConsoleObject* HotReloadCmd = nullptr;
|
||||
IConsoleObject* ReloadModuleCmd = nullptr;
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class UnrealLuaDemoEditorTarget : TargetRules
|
||||
{
|
||||
public UnrealLuaDemoEditorTarget(TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Editor;
|
||||
DefaultBuildSettings = BuildSettingsVersion.V7;
|
||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_8;
|
||||
ExtraModuleNames.Add("UnrealLuaDemo");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user