Skip to content

Commit

Permalink
Merge pull request #519 from zjhongxian/master
Browse files Browse the repository at this point in the history
fixed many bugs
  • Loading branch information
zjhongxian authored May 26, 2023
2 parents fc35ebf + 68744ec commit d8cfa38
Show file tree
Hide file tree
Showing 28 changed files with 132 additions and 411 deletions.
4 changes: 4 additions & 0 deletions Content/Lua/TestMap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ function TestMap:ReceiveBeginPlay()
test()
end

function TestMap:update()

end

return Class(ni, nil, TestMap)
14 changes: 6 additions & 8 deletions Plugins/slua_unreal/Source/slua_unreal/Private/LuaActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ ALuaActor::ALuaActor(const FObjectInitializer& ObjectInitializer)
{
}

void ALuaActor::PostInitializeComponents()
{
Super::PostInitializeComponents();

CallReceivePreRep(LuaFilePath);
TryHookActorComponents();
}

void ALuaActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
Expand All @@ -30,6 +22,12 @@ FString ALuaActor::GetLuaFilePath_Implementation() const
return LuaFilePath;
}

void ALuaActor::PostInitializeComponents()
{
Super::PostInitializeComponents();
ILuaOverriderInterface::PostLuaHook();
}

void ALuaActor::RegistLuaTick(float TickInterval)
{
EnableLuaTick = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ ULuaActorComponent::ULuaActorComponent(const FObjectInitializer& ObjectInitializ
bWantsInitializeComponent = true;
}

void ULuaActorComponent::InitializeComponent()
{
Super::InitializeComponent();

CallReceivePreRep(LuaFilePath);
}

void ULuaActorComponent::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
Expand Down Expand Up @@ -42,6 +35,13 @@ void ULuaActorComponent::UnRegistLuaTick()
state->unRegistLuaTick(this);
}

void ULuaActorComponent::InitializeComponent()
{
Super::InitializeComponent();

TryHook();
}

void ULuaActorComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ namespace NS_SLUA
FProperty* prop = *it;
uint64 propflag = prop->GetPropertyFlags();

FOutParmRec* out = nullptr;
if (prop->HasAnyPropertyFlags(CPF_OutParm))
{
outParmRecProps.Add(prop);
}

FCheckerInfo checkerInfo = {false, false, false, propIndex, prop->GetOffset_ForInternal(), prop};
FCheckerInfo checkerInfo = {false, false, false, false, propIndex, prop->GetOffset_ForInternal(), prop};
FCheckerInfo* checkerRef = &checkerInfo;
if (!prop->HasAnyPropertyFlags(CPF_NoDestructor) &&
!(IsReferenceParam(prop->PropertyFlags, func) && LuaObject::getReferencer(prop)))
if (!prop->HasAnyPropertyFlags(CPF_NoDestructor))
{
checkerInfo.bInit = true;
checkerInfo.bReference = IsReferenceParam(prop->PropertyFlags, func) && LuaObject::getReferencer(prop);
paramsChecker.Add(checkerInfo);

checkerRef = &paramsChecker.Top();
}

Expand Down Expand Up @@ -152,8 +152,8 @@ namespace NS_SLUA
auto funcPtr = cache.Find(inFunc);
if (funcPtr)
{
cache.Remove(inFunc);
delete *funcPtr;
cache.Remove(inFunc);
return true;
}

Expand Down Expand Up @@ -230,7 +230,7 @@ namespace NS_SLUA
for (auto& checkerInfo : paramsChecker)
{
auto prop = checkerInfo.prop;
if (checkerInfo.bInit && (lua_type(L, i) == LUA_TUSERDATA))
if (checkerInfo.bInit && !(checkerInfo.bReference && (lua_type(L, i) == LUA_TUSERDATA)))
{
if (!prop->HasAnyPropertyFlags(CPF_ZeroConstructor))
{
Expand Down Expand Up @@ -353,7 +353,7 @@ namespace NS_SLUA
for (auto& checkerInfo : paramsChecker)
{
auto prop = checkerInfo.prop;
if (checkerInfo.bInit && (lua_type(L, i) == LUA_TUSERDATA))
if (checkerInfo.bInit && !(checkerInfo.bReference && (lua_type(L, i) == LUA_TUSERDATA)))
{
if (!prop->HasAnyPropertyFlags(CPF_ZeroConstructor))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ FString ALuaGameMode::GetLuaFilePath_Implementation() const
{
return LuaFilePath;
}

void ALuaGameMode::PostInitializeComponents()
{
Super::PostInitializeComponents();

CallReceivePreRep(LuaFilePath);
TryHookActorComponents();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ FString ALuaGameState::GetLuaFilePath_Implementation() const
return LuaFilePath;
}

void ALuaGameState::PostInitializeComponents()
{
Super::PostInitializeComponents();

CallReceivePreRep(LuaFilePath);
TryHookActorComponents();
}

void ALuaGameState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void ALuaLevelScriptActor::onLuaStateInit(NS_SLUA::lua_State* L)
{
if (!HasAnyFlags(RF_ClassDefaultObject | RF_ArchetypeObject))
{
NS_SLUA::LuaState::hookObject(nullptr, this);
NS_SLUA::LuaState::hookObject(nullptr, this, true);
}
}

Expand Down
Loading

0 comments on commit d8cfa38

Please sign in to comment.