Skip to content

Commit

Permalink
Merge pull request #599 from zjhongxian/master
Browse files Browse the repository at this point in the history
fixed bugs
  • Loading branch information
zjhongxian authored Jun 26, 2024
2 parents 02d658f + b074a67 commit ea2a2bc
Show file tree
Hide file tree
Showing 9 changed files with 8,974 additions and 6,326 deletions.
4 changes: 0 additions & 4 deletions Plugins/slua_unreal/Source/slua_unreal/Private/LuaArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,7 @@ namespace NS_SLUA {

CallInfo* ci = L->ci;

#if LUA_VERSION_NUM > 503
auto func = s2v(ci->func);
#else
auto func = ci->func;
#endif
setobjs2s(L, L->top, func);
L->top++;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ bool FLuaNetSerialization::CompareProperties(UObject* obj, NS_SLUA::FLuaNetSeria
if (newArrayNum > NS_SLUA::ClassLuaReplicated::MaxArrayLimit)
{
UE_LOG(Slua, Error, TEXT("FLuaNetSerialization::CompareProperties Error: Object[%s]'s replicated property[%s] array num[%d] is greater than MaxArrayLimit!"),
*obj->GetFullName(), *flatProp->GetName(), newArrayNum);
*obj->GetFullName(), *classLuaReplicated->replicatedIndexToNameMap[propIndex], newArrayNum);
}
int32 newLen = FMath::Min(newArrayNum, NS_SLUA::ClassLuaReplicated::MaxArrayLimit);
int32 oldLen = oldArrayHelper.Num();
Expand Down Expand Up @@ -849,7 +849,7 @@ bool FLuaNetSerialization::UpdateChangeListMgr(NS_SLUA::FLuaNetSerializationProx
return false;
}

if (proxy.dirtyMark.IsEmpty())
if (proxy.flatDirtyMark.IsEmpty())
{
proxy.bDirtyThisFrame = false;
proxy.lastReplicationFrame = ReplicationFrame;
Expand Down
20 changes: 18 additions & 2 deletions Plugins/slua_unreal/Source/slua_unreal/Private/LuaObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#endif

#include "LuaObject.h"
#if LUA_VERSION_NUM >= 504
#include <lgc.h>
#endif
#include "LuaDelegate.h"
#include "LatentDelegate.h"
#include "UObject/Class.h"
Expand Down Expand Up @@ -895,13 +898,16 @@ namespace NS_SLUA {
if (type == LUA_TFUNCTION)
{
// get metatable __index function's upvalue[0]
#if LUA_VERSION_NUM > 503
#if LUA_VERSION_NUM >= 504
#define G(L) (L->l_G)
TValue* v = s2v(L->top - 1);
CClosure* f = clCvalue(v);
setobj2s(L, L->top - 1, &f->upvalue[0]);
#undef G
#else
CClosure* f = clCvalue(L->top - 1);
#endif
setobj2s(L, L->top - 1, &f->upvalue[0]);
#endif

lua_pushvalue(L, -2); // push self table
lua_pushvalue(L, keyIndex); // push key
Expand Down Expand Up @@ -971,7 +977,11 @@ namespace NS_SLUA {

auto prop = (FProperty*)pvalue(&f->upvalue[0]);
void* pusher = pvalue(&f->upvalue[1]);
#if LUA_VERSION_NUM >= 504
bool bReferencePusher = !l_isfalse(&f->upvalue[3]);
#else
bool bReferencePusher = !!bvalue(&f->upvalue[3]);
#endif
if (bReferencePusher)
{
auto ud = reinterpret_cast<GenericUserData*>(lua_touserdata(L, 1));
Expand Down Expand Up @@ -1016,7 +1026,13 @@ namespace NS_SLUA {

auto prop = (FProperty*)pvalue(&f->upvalue[0]);
void* pusher = pvalue(&f->upvalue[1]);

#if LUA_VERSION_NUM >= 504
bool bReferencePusher = !l_isfalse(&f->upvalue[3]);
#else
bool bReferencePusher = !!bvalue(&f->upvalue[3]);
#endif

if (bReferencePusher)
{
return pushReferenceAndCache((ReferencePusherPropertyFunction)pusher, L,
Expand Down
22 changes: 17 additions & 5 deletions Plugins/slua_unreal/Source/slua_unreal/Private/LuaOverrider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void ULuaOverrider::luaOverrideFunc(UObject* Context, FFrame& Stack, RESULT_DECL

if (bCallFromNative || !Stack.OutParms || bContextOp)
{
if (RESULT_PARAM && func->ReturnValueOffset != MAX_uint16)
if (!bCallSuper && (RESULT_PARAM && func->ReturnValueOffset != MAX_uint16))
{
auto prop = func->GetReturnProperty();
FOutParmRec* out = bContextOp ? nullptr : Stack.OutParms;
Expand Down Expand Up @@ -922,7 +922,7 @@ namespace NS_SLUA
classAddedFuncs.Remove(cls);
if (cls->IsValidLowLevel())
{
cacheNativeFuncs.Remove(cls);
cacheNativeFuncs.Remove(cls);
}
#endif
classHookedFuncNames.Remove(cls);
Expand Down Expand Up @@ -1249,14 +1249,23 @@ namespace NS_SLUA
lua_pop(L, 2);
#endif

if (!overridedClasses.Contains(cls)) {
if (!overridedClasses.Contains(cls) || bHookInstancedObj) {
SCOPE_CYCLE_COUNTER(STAT_LuaOverrider_do_bindOverrideFuncs);

overridedClasses.Add(cls);
overridedClasses.Emplace(cls);

TSet<FName> funcNames;
getLuaFunctions(L, funcNames, luaModule);

if (bHookInstancedObj)
{
auto hookedFuncsPtr = classHookedFuncNames.Find(cls);
if (hookedFuncsPtr)
{
funcNames = hookedFuncsPtr->Difference(funcNames);
}
}

int hookCounter = 0;
for (auto& funcName : funcNames) {
UFunction* func = cls->FindFunctionByName(funcName, EIncludeSuperFlag::IncludeSuper);
Expand All @@ -1272,7 +1281,10 @@ namespace NS_SLUA

luaNet->addClassRPC(L, cls, luaFilePath);
//NS_SLUA::Log::Log("LuaOverrider::bindOverrideFuncs luafile:%s totalFuncs:%d, cost:%.5fs", TCHAR_TO_UTF8(*luaFilePath), hookCounter, FPlatformTime::Seconds() - CurTime);
classHookedFuncNames.Add(cls, funcNames);
if (!bHookInstancedObj)
{
classHookedFuncNames.Emplace(cls, funcNames);
}
}

bool bNetReplicated = false;
Expand Down
2 changes: 1 addition & 1 deletion Plugins/slua_unreal/Source/slua_unreal/Private/LuaSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ namespace NS_SLUA
}
else
{
checkSlow(Slack >= 0);
checkSlow(slack >= 0);
const int32 OldNum = num();
if (OldNum || slack)
{
Expand Down
Loading

0 comments on commit ea2a2bc

Please sign in to comment.