Skip to content

Commit

Permalink
Merge branch 'develop' into feature/cdo
Browse files Browse the repository at this point in the history
  • Loading branch information
forsakenyang committed Jun 8, 2022
2 parents 3ebffb3 + c9604f0 commit dcd02bb
Show file tree
Hide file tree
Showing 36 changed files with 313 additions and 123 deletions.
2 changes: 1 addition & 1 deletion Config/DefaultEditor.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
+EngineTargetsSettings=(Name="Category",Guid=14B8DEE642A6A7AFEB5A28B959EC373A,TargetDependencies=,AdditionalManifestDependencies=,RequiredModuleNames=,GatherFromTextFiles=(IsEnabled=False,SearchDirectories=,ExcludePathWildcards=,FileExtensions=((Pattern="h"),(Pattern="cpp"),(Pattern="ini")),ShouldGatherFromEditorOnlyData=False),GatherFromPackages=(IsEnabled=False,IncludePathWildcards=,ExcludePathWildcards=,FileExtensions=((Pattern="umap"),(Pattern="uasset")),Collections=,ExcludeClasses=,ShouldExcludeDerivedClasses=False,ShouldGatherFromEditorOnlyData=False,SkipGatherCache=False),GatherFromMetaData=(IsEnabled=True,IncludePathWildcards=((Pattern="Source/Editor/*"),(Pattern="Source/Runtime/*"),(Pattern="Source/Developer/*")),ExcludePathWildcards=((Pattern="Source/Developer/NoRedist/CommunityPortalServices/*")),KeySpecifications=((MetaDataKey=(Name="Category"),TextNamespace="UObjectCategory",TextKeyPattern=(Pattern="{FieldPath}"))),ShouldGatherFromEditorOnlyData=True),ExportSettings=(CollapseMode=IdenticalTextIdAndSource,POFormat=Unreal,ShouldPersistCommentsOnExport=False,ShouldAddSourceLocationsAsComments=True),CompileSettings=(SkipSourceCheck=False,ValidateFormatPatterns=True,ValidateSafeWhitespace=False),ImportDialogueSettings=(RawAudioPath=(Path=""),ImportedDialogueFolder="ImportedDialogue",bImportNativeAsSource=False),NativeCultureIndex=0,SupportedCulturesStatistics=((CultureName="en"),(CultureName="es"),(CultureName="ja"),(CultureName="ko"),(CultureName="pt-BR"),(CultureName="zh-CN")))
-GameTargetsSettings=(Name="Game",Guid=AE0EA34A45461A25BA65A391026F19F8,TargetDependencies=(33482D004789784C9DA695A682ACCA1B,AC8BFD2A41A2FB2893BB8EA0AF903E6D),AdditionalManifestDependencies=,RequiredModuleNames=,GatherFromTextFiles=(IsEnabled=False,SearchDirectories=,ExcludePathWildcards=,FileExtensions=((Pattern="h"),(Pattern="cpp"),(Pattern="ini"))),GatherFromPackages=(IsEnabled=False,IncludePathWildcards=,ExcludePathWildcards=,FileExtensions=((Pattern="umap"),(Pattern="uasset")),ShouldGatherFromEditorOnlyData=False),GatherFromMetaData=(IsEnabled=False,IncludePathWildcards=,ExcludePathWildcards=,KeySpecifications=,ShouldGatherFromEditorOnlyData=False),NativeCultureIndex=-1,SupportedCulturesStatistics=((CultureName="en")))
+GameTargetsSettings=(Name="Game",Guid=AE0EA34A45461A25BA65A391026F19F8,TargetDependencies=(33482D004789784C9DA695A682ACCA1B,AC8BFD2A41A2FB2893BB8EA0AF903E6D),AdditionalManifestDependencies=,RequiredModuleNames=,GatherFromTextFiles=(IsEnabled=False,SearchDirectories=,ExcludePathWildcards=,FileExtensions=((Pattern="h"),(Pattern="cpp"),(Pattern="ini")),ShouldGatherFromEditorOnlyData=False),GatherFromPackages=(IsEnabled=False,IncludePathWildcards=,ExcludePathWildcards=,FileExtensions=((Pattern="umap"),(Pattern="uasset")),Collections=,ExcludeClasses=,ShouldExcludeDerivedClasses=False,ShouldGatherFromEditorOnlyData=False,SkipGatherCache=False),GatherFromMetaData=(IsEnabled=False,IncludePathWildcards=,ExcludePathWildcards=,KeySpecifications=,ShouldGatherFromEditorOnlyData=False),ExportSettings=(CollapseMode=IdenticalTextIdAndSource,POFormat=Unreal,ShouldPersistCommentsOnExport=False,ShouldAddSourceLocationsAsComments=True),CompileSettings=(SkipSourceCheck=False,ValidateFormatPatterns=True,ValidateSafeWhitespace=False),ImportDialogueSettings=(RawAudioPath=(Path=""),ImportedDialogueFolder="ImportedDialogue",bImportNativeAsSource=False),NativeCultureIndex=-1,SupportedCulturesStatistics=((CultureName="en")))
+GameTargetsSettings=(Name="UnLua",Guid=95A7F1D94E4BB126E85EC5A4A4B79AD4,TargetDependencies=,AdditionalManifestDependencies=,RequiredModuleNames=,GatherFromTextFiles=(IsEnabled=True,SearchDirectories=((Path="Plugins/UnLua/Source")),ExcludePathWildcards=,FileExtensions=((Pattern="h"),(Pattern="cpp"),(Pattern="ini")),ShouldGatherFromEditorOnlyData=False),GatherFromPackages=(IsEnabled=False,IncludePathWildcards=,ExcludePathWildcards=((Pattern="Content/L10N/*")),FileExtensions=((Pattern="umap"),(Pattern="uasset")),Collections=,ExcludeClasses=,ShouldExcludeDerivedClasses=False,ShouldGatherFromEditorOnlyData=False,SkipGatherCache=False),GatherFromMetaData=(IsEnabled=False,IncludePathWildcards=,ExcludePathWildcards=,KeySpecifications=,ShouldGatherFromEditorOnlyData=False),ExportSettings=(CollapseMode=IdenticalTextIdAndSource,POFormat=Unreal,ShouldPersistCommentsOnExport=False,ShouldAddSourceLocationsAsComments=True),CompileSettings=(SkipSourceCheck=False,ValidateFormatPatterns=True,ValidateSafeWhitespace=False),ImportDialogueSettings=(RawAudioPath=(Path=""),ImportedDialogueFolder="ImportedDialogue",bImportNativeAsSource=False),NativeCultureIndex=0,SupportedCulturesStatistics=((CultureName="zh-Hans")))
+GameTargetsSettings=(Name="UnLua",Guid=95A7F1D94E4BB126E85EC5A4A4B79AD4,TargetDependencies=(0F116534468918AEA432DD8C77703BA8,AE89AECB47475F420D0D69A5547515DC,14B8DEE642A6A7AFEB5A28B959EC373A,33482D004789784C9DA695A682ACCA1B,AC8BFD2A41A2FB2893BB8EA0AF903E6D),AdditionalManifestDependencies=,RequiredModuleNames=,GatherFromTextFiles=(IsEnabled=True,SearchDirectories=((Path="Plugins/UnLua/Source")),ExcludePathWildcards=,FileExtensions=((Pattern="h"),(Pattern="cpp"),(Pattern="ini")),ShouldGatherFromEditorOnlyData=True),GatherFromPackages=(IsEnabled=False,IncludePathWildcards=,ExcludePathWildcards=((Pattern="Content/L10N/*")),FileExtensions=((Pattern="umap"),(Pattern="uasset")),Collections=,ExcludeClasses=,ShouldExcludeDerivedClasses=False,ShouldGatherFromEditorOnlyData=False,SkipGatherCache=False),GatherFromMetaData=(IsEnabled=True,IncludePathWildcards=((Pattern="Plugins/UnLua/Source/*")),ExcludePathWildcards=,KeySpecifications=((MetaDataKey=(Name="ToolTip"),TextNamespace="UObjectToolTips",TextKeyPattern=(Pattern="{FieldPath}")),(MetaDataKey=(Name="DisplayName"),TextNamespace="UObjectDisplayNames",TextKeyPattern=(Pattern="{FieldPath}")),(MetaDataKey=(Name="Category"),TextNamespace="UObjectCategory",TextKeyPattern=(Pattern="{FieldPath}"))),ShouldGatherFromEditorOnlyData=True),ExportSettings=(CollapseMode=IdenticalTextIdAndSource,POFormat=Unreal,ShouldPersistCommentsOnExport=False,ShouldAddSourceLocationsAsComments=True),CompileSettings=(SkipSourceCheck=False,ValidateFormatPatterns=True,ValidateSafeWhitespace=False),ImportDialogueSettings=(RawAudioPath=(Path=""),ImportedDialogueFolder="ImportedDialogue",bImportNativeAsSource=False),NativeCultureIndex=0,SupportedCulturesStatistics=((CultureName="zh-Hans")))

[Internationalization]
+LocalizationPaths=%GAMEDIR%Content/Localization/UnLua
Expand Down
25 changes: 22 additions & 3 deletions Config/Localization/UnLua_Gather.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[CommonSettings]
ManifestDependencies=../../Program Files/Epic Games/UE_4.26/Engine/Content/Localization/ToolTips/ToolTips.manifest
ManifestDependencies=../../Program Files/Epic Games/UE_4.26/Engine/Content/Localization/Keywords/Keywords.manifest
ManifestDependencies=../../Program Files/Epic Games/UE_4.26/Engine/Content/Localization/Category/Category.manifest
ManifestDependencies=../../Program Files/Epic Games/UE_4.26/Engine/Content/Localization/Engine/Engine.manifest
ManifestDependencies=../../Program Files/Epic Games/UE_4.26/Engine/Content/Localization/Editor/Editor.manifest
SourcePath=Content/Localization/UnLua
DestinationPath=Content/Localization/UnLua
ManifestName=UnLua.manifest
Expand All @@ -13,15 +18,29 @@ ExcludePathFilters=Config/Localization/*
FileNameFilters=*.h
FileNameFilters=*.cpp
FileNameFilters=*.ini
ShouldGatherFromEditorOnlyData=false
ShouldGatherFromEditorOnlyData=true

[GatherTextStep1]
CommandletClass=GenerateGatherManifest
CommandletClass=GatherTextFromMetadata
IncludePathFilters=Plugins/UnLua/Source/*
InputKeys=ToolTip
InputKeys=DisplayName
InputKeys=Category
OutputNamespaces=UObjectToolTips
OutputNamespaces=UObjectDisplayNames
OutputNamespaces=UObjectCategory
OutputKeys="{FieldPath}"
OutputKeys="{FieldPath}"
OutputKeys="{FieldPath}"
ShouldGatherFromEditorOnlyData=true

[GatherTextStep2]
CommandletClass=GenerateGatherArchive
CommandletClass=GenerateGatherManifest

[GatherTextStep3]
CommandletClass=GenerateGatherArchive

[GatherTextStep4]
CommandletClass=GenerateTextLocalizationReport
bWordCountReport=true
WordCountReportName=UnLua.csv
Expand Down
13 changes: 13 additions & 0 deletions Content/Localization/UnLua/UnLua.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Date/Time,Word Count,zh-Hans
2022.03.17-11.26.16,101,101
2022.05.28-01.30.11,166,166
2022.06.07-12.00.37,183,183
2022.06.07-12.18.21,187,187
2022.06.07-12.23.19,321,321
2022.06.07-12.38.33,187,187
2022.06.07-12.40.09,515,515
2022.06.07-12.44.45,585,585
2022.06.07-13.04.33,515,515
2022.06.07-13.08.26,585,585
2022.06.07-13.27.43,599,599
2022.06.07-18.25.31,562,562
2022.06.07-19.09.46,606,606
2022.06.07-21.37.50,504,504
2022.06.07-22.44.41,568,568
Binary file modified Content/Localization/UnLua/UnLua.manifest
Binary file not shown.
Binary file modified Content/Localization/UnLua/zh-Hans/UnLua.archive
Binary file not shown.
Binary file modified Content/Localization/UnLua/zh-Hans/UnLua.locres
Binary file not shown.
Binary file modified Content/Tutorials/10_Replications/ChatCharacter.uasset
Binary file not shown.
4 changes: 4 additions & 0 deletions Docs/CN/ConsoleCommand.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ lua.do print("hello world")
```
lua.do test1.test2
```

### lua.gc

在默认环境强制执行一次垃圾回收。
13 changes: 13 additions & 0 deletions Plugins/UnLua/Content/Localization/UnLua/UnLua.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Date/Time,Word Count,zh-Hans
2022.03.17-11.26.16,101,101
2022.05.28-01.30.11,166,166
2022.06.07-12.00.37,183,183
2022.06.07-12.18.21,187,187
2022.06.07-12.23.19,321,321
2022.06.07-12.38.33,187,187
2022.06.07-12.40.09,515,515
2022.06.07-12.44.45,585,585
2022.06.07-13.04.33,515,515
2022.06.07-13.08.26,585,585
2022.06.07-13.27.43,599,599
2022.06.07-18.25.31,562,562
2022.06.07-19.09.46,606,606
2022.06.07-21.37.50,504,504
2022.06.07-22.44.41,568,568
Binary file modified Plugins/UnLua/Content/Localization/UnLua/UnLua.manifest
Binary file not shown.
Binary file modified Plugins/UnLua/Content/Localization/UnLua/zh-Hans/UnLua.archive
Binary file not shown.
Binary file modified Plugins/UnLua/Content/Localization/UnLua/zh-Hans/UnLua.locres
Binary file not shown.
2 changes: 2 additions & 0 deletions Plugins/UnLua/Source/UnLua/Private/Containers/LuaArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class FLuaArray
{
// allocate cache for a single element
ElementCache = FMemory::Malloc(ElementSize, Inner->GetAlignment());
UNLUA_STAT_MEMORY_ALLOC(ElementCache, ContainerElementCache);
}

~FLuaArray()
Expand All @@ -62,6 +63,7 @@ class FLuaArray
Clear();
delete ScriptArray;
}
UNLUA_STAT_MEMORY_FREE(ElementCache, ContainerElementCache);
FMemory::Free(ElementCache);
}

Expand Down
3 changes: 3 additions & 0 deletions Plugins/UnLua/Source/UnLua/Private/Containers/LuaMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class FLuaMap
StructBuilder.AddMember(InValueInterface->GetSize(), InValueInterface->GetAlignment());
// allocate cache for a key-value pair with alignment
ElementCache = FMemory::Malloc(StructBuilder.GetSize(), StructBuilder.GetAlignment());
UNLUA_STAT_MEMORY_ALLOC(ElementCache, ContainerElementCache);
}

FLuaMap(const FScriptMap *InScriptMap, TLuaContainerInterface<FLuaMap> *InMapInterface, FScriptMapFlag Flag = OwnedByOther)
Expand All @@ -75,6 +76,7 @@ class FLuaMap
StructBuilder.AddMember(ValueInterface->GetSize(), ValueInterface->GetAlignment());
// allocate cache for a key-value pair with alignment
ElementCache = FMemory::Malloc(StructBuilder.GetSize(), StructBuilder.GetAlignment());
UNLUA_STAT_MEMORY_ALLOC(ElementCache, ContainerElementCache);
}
}

Expand All @@ -85,6 +87,7 @@ class FLuaMap
Clear();
delete Map;
}
UNLUA_STAT_MEMORY_FREE(ElementCache, ContainerElementCache);
FMemory::Free(ElementCache);
}

Expand Down
3 changes: 3 additions & 0 deletions Plugins/UnLua/Source/UnLua/Private/Containers/LuaSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FLuaSet
{
// allocate cache for a single element
ElementCache = FMemory::Malloc(ElementInterface->GetSize(), ElementInterface->GetAlignment());
UNLUA_STAT_MEMORY_ALLOC(ElementCache, ContainerElementCache);
}

FLuaSet(const FScriptSet *InScriptSet, TLuaContainerInterface<FLuaSet> *Interface, FScriptSetFlag Flag = OwnedByOther)
Expand All @@ -41,6 +42,7 @@ class FLuaSet

// allocate cache for a single element
ElementCache = FMemory::Malloc(ElementInterface->GetSize(), ElementInterface->GetAlignment());
UNLUA_STAT_MEMORY_ALLOC(ElementCache, ContainerElementCache);
}

~FLuaSet()
Expand All @@ -50,6 +52,7 @@ class FLuaSet
Clear();
delete Set;
}
UNLUA_STAT_MEMORY_FREE(ElementCache, ContainerElementCache);
FMemory::Free(ElementCache);
}

Expand Down
25 changes: 3 additions & 22 deletions Plugins/UnLua/Source/UnLua/Private/LuaEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,7 @@ namespace UnLua
{
if (nsize == 0)
{
#if STATS
const uint32 Size = FMemory::GetAllocSize(ptr);
DEC_MEMORY_STAT_BY(STAT_UnLua_Lua_Memory, Size);
#endif
UNLUA_STAT_MEMORY_FREE(ptr, Lua);
FMemory::Free(ptr);
return nullptr;
}
Expand All @@ -587,28 +584,12 @@ namespace UnLua
if (!ptr)
{
Buffer = FMemory::Malloc(nsize);
#if STATS
const uint32 Size = FMemory::GetAllocSize(Buffer);
INC_MEMORY_STAT_BY(STAT_UnLua_Lua_Memory, Size);
#endif
UNLUA_STAT_MEMORY_ALLOC(Buffer, Lua);
}
else
{
#if STATS
const uint32 OldSize = FMemory::GetAllocSize(ptr);
#endif
UNLUA_STAT_MEMORY_REALLOC(ptr, Buffer, Lua);
Buffer = FMemory::Realloc(ptr, nsize);
#if STATS
const uint32 NewSize = FMemory::GetAllocSize(Buffer);
if (NewSize > OldSize)
{
INC_MEMORY_STAT_BY(STAT_UnLua_Lua_Memory, NewSize - OldSize);
}
else
{
DEC_MEMORY_STAT_BY(STAT_UnLua_Lua_Memory, OldSize - NewSize);
}
#endif
}
return Buffer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ FFunctionDesc::FFunctionDesc(UFunction *InFunction, FParameterCollection *InDefa
{
Buffer = FMemory::Malloc(InFunction->ParmsSize, 16);
FMemory::Memzero(Buffer, InFunction->ParmsSize);
#if STATS
const uint32 Size = FMemory::GetAllocSize(Buffer);
INC_MEMORY_STAT_BY(STAT_UnLua_PersistentParamBuffer_Memory, Size);
#endif
UNLUA_STAT_MEMORY_ALLOC(Buffer, Lua)
}
#endif

Expand Down Expand Up @@ -97,10 +94,7 @@ FFunctionDesc::FFunctionDesc(UFunction *InFunction, FParameterCollection *InDefa
// pre-create OutParmRec for 'out' property
#if !SUPPORTS_RPC_CALL
FOutParmRec *Out = (FOutParmRec*)FMemory::Malloc(sizeof(FOutParmRec), alignof(FOutParmRec));
#if STATS
const uint32 Size = FMemory::GetAllocSize(Out);
INC_MEMORY_STAT_BY(STAT_UnLua_OutParmRec_Memory, Size);
#endif
UNLUA_STAT_MEMORY_ALLOC(Out, OutParmRec);
Out->PropAddr = Property->ContainerPtrToValuePtr<uint8>(Buffer);
Out->Property = Property;
if (CurrentOutParmRec)
Expand Down Expand Up @@ -155,10 +149,7 @@ FFunctionDesc::~FFunctionDesc()
#if ENABLE_PERSISTENT_PARAM_BUFFER
if (Buffer)
{
#if STATS
const uint32 Size = FMemory::GetAllocSize(Buffer);
DEC_MEMORY_STAT_BY(STAT_UnLua_PersistentParamBuffer_Memory, Size);
#endif
UNLUA_STAT_MEMORY_FREE(Buffer, PersistentParamBuffer);
FMemory::Free(Buffer);
}
#endif
Expand All @@ -168,10 +159,7 @@ FFunctionDesc::~FFunctionDesc()
while (OutParmRec)
{
FOutParmRec *NextOut = OutParmRec->NextOutParm;
#if STATS
const uint32 Size = FMemory::GetAllocSize(OutParmRec);
DEC_MEMORY_STAT_BY(STAT_UnLua_OutParmRec_Memory, Size);
#endif
UNLUA_STAT_MEMORY_FREE(OutParmRec, OutParmRec);
FMemory::Free(OutParmRec);
OutParmRec = NextOut;
}
Expand Down
17 changes: 17 additions & 0 deletions Plugins/UnLua/Source/UnLua/Private/UnLuaConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace UnLua
*LOCTEXT("CommandText_DoFile", "Runs the given module path in lua env.").ToString(),
FConsoleCommandWithArgsDelegate::CreateRaw(this, &FUnLuaConsoleCommands::DoFile)
),
CollectGarbageCommand(
TEXT("lua.gc"),
*LOCTEXT("CommandText_CollectGarbage", "Force collect garbage in lua env.").ToString(),
FConsoleCommandWithArgsDelegate::CreateRaw(this, &FUnLuaConsoleCommands::CollectGarbage)
),
Module(InModule)
{
}
Expand Down Expand Up @@ -62,6 +67,18 @@ namespace UnLua
const auto Chunk = FString::Printf(Format, *Args[0]);
Env->DoString(Chunk);
}

void FUnLuaConsoleCommands::CollectGarbage(const TArray<FString>& Args) const
{
auto Env = Module->GetEnv();
if (!Env)
{
UE_LOG(LogUnLua, Warning, TEXT("no available lua env found to collect garbage."));
return;
}

Env->GC();
}
}

#undef LOCTEXT_NAMESPACE
4 changes: 4 additions & 0 deletions Plugins/UnLua/Source/UnLua/Private/UnLuaConsoleCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ namespace UnLua

FAutoConsoleCommand DoFileCommand;

FAutoConsoleCommand CollectGarbageCommand;

explicit FUnLuaConsoleCommands(IUnLuaModule* InModule);

void Do(const TArray<FString>& Args) const;

void DoFile(const TArray<FString>& Args) const;

void CollectGarbage(const TArray<FString>& Args) const;

private:
IUnLuaModule* Module;
};
Expand Down
1 change: 1 addition & 0 deletions Plugins/UnLua/Source/UnLua/Private/UnLuaLegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DEFINE_STAT(STAT_UnLua_Lua_Memory);
DEFINE_STAT(STAT_UnLua_PersistentParamBuffer_Memory);
DEFINE_STAT(STAT_UnLua_OutParmRec_Memory);
DEFINE_STAT(STAT_UnLua_ContainerElementCache_Memory);

namespace UnLua
{
Expand Down
33 changes: 33 additions & 0 deletions Plugins/UnLua/Source/UnLua/Private/UnLuaPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,39 @@ DECLARE_STATS_GROUP(TEXT("UnLua"), STATGROUP_UnLua, STATCAT_Advanced);
DECLARE_MEMORY_STAT_EXTERN(TEXT("Lua Memory"), STAT_UnLua_Lua_Memory, STATGROUP_UnLua, /*UNLUA_API*/);
DECLARE_MEMORY_STAT_EXTERN(TEXT("Persistent Parameter Buffer Memory"), STAT_UnLua_PersistentParamBuffer_Memory, STATGROUP_UnLua, /*UNLUA_API*/);
DECLARE_MEMORY_STAT_EXTERN(TEXT("OutParmRec Memory"), STAT_UnLua_OutParmRec_Memory, STATGROUP_UnLua, /*UNLUA_API*/);
DECLARE_MEMORY_STAT_EXTERN(TEXT("Container Element Cache Memory"), STAT_UnLua_ContainerElementCache_Memory, STATGROUP_UnLua, /*UNLUA_API*/);

#define UNLUA_STAT_MEMORY_ALLOC(Pointer, CounterName) \
const auto _AllocedSize = FMemory::GetAllocSize(Pointer); \
INC_MEMORY_STAT_BY(STAT_UnLua_##CounterName##_Memory, _AllocedSize);

#define UNLUA_STAT_MEMORY_FREE(PointerName, CounterName) \
const auto _FreedSize = FMemory::GetAllocSize(PointerName); \
DEC_MEMORY_STAT_BY(STAT_UnLua_##CounterName##_Memory, _FreedSize);

#define UNLUA_STAT_MEMORY_REALLOC(Pointer, NewPointer, CounterName) \
struct FReallocGuard { \
uint32 OldSize; \
void* Ptr; \
void** NewPtr; \
~FReallocGuard() { \
const auto NewSize = FMemory::GetAllocSize(*NewPtr); \
if (NewSize > OldSize) \
INC_MEMORY_STAT_BY(STAT_UnLua_##CounterName##_Memory, NewSize - OldSize) \
else \
DEC_MEMORY_STAT_BY(STAT_UnLua_##CounterName##_Memory, OldSize - NewSize) \
} \
} _ReallocGuard; \
_ReallocGuard.OldSize = FMemory::GetAllocSize(Pointer); \
_ReallocGuard.Ptr = Pointer; \
_ReallocGuard.NewPtr = &NewPointer; \

#else

#define UNLUA_STAT_MEMORY_ALLOC(Pointer, CounterName)
#define UNLUA_STAT_MEMORY_FREE(PointerName, CounterName)
#define UNLUA_STAT_MEMORY_REALLOC(Pointer, NewPointer, CounterName)

#endif

UNLUA_API extern FString GLuaSrcRelativePath;
Expand Down
6 changes: 4 additions & 2 deletions Plugins/UnLua/Source/UnLua/Public/UnLuaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class UNLUA_API UUnLuaSettings : public UObject
public:
UUnLuaSettings(const FObjectInitializer& ObjectInitializer);

UPROPERTY(Config, EditAnywhere, Category=Runtime, Meta=(ToolTip="Prevent from infinite loops in lua. Timeout in seconds."))
/** Prevent from infinite loops in lua. Timeout in seconds. */
UPROPERTY(Config, EditAnywhere, Category="Runtime")
int32 DeadLoopCheck = 0;

UPROPERTY(Config, EditAnywhere, Category=Runtime, Meta=(AllowAbstract="false", DisplayName="LuaEnvLocator"))
/** Class of LuaEnvLocator, which handles lua env locating for each UObject. */
UPROPERTY(Config, EditAnywhere, Category="Runtime", Meta=(AllowAbstract="false"))
TSubclassOf<ULuaEnvLocator> EnvLocatorClass = ULuaEnvLocator::StaticClass();

UPROPERTY(Config, EditAnywhere, Category=Runtime, Meta=(AllowAbstract="false", DisplayName="LuaModuleLocator"))
Expand Down
Loading

0 comments on commit dcd02bb

Please sign in to comment.