Skip to content

Commit

Permalink
Merge pull request #536 from zjhongxian/master
Browse files Browse the repository at this point in the history
fix bugs and add clone api for struct
  • Loading branch information
zjhongxian authored Jul 12, 2023
2 parents d6fa617 + 176bf29 commit 6b72315
Show file tree
Hide file tree
Showing 19 changed files with 30,923 additions and 7,420 deletions.
28 changes: 18 additions & 10 deletions Plugins/slua_unreal/Source/slua_unreal/Private/LuaObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "lstate.h"
#include "LuaBlueprintLibrary.h" // Comment For PUBG Mobile
#include "LuaFunctionAccelerator.h"
#include "LuaProfiler.h"
#include "LuaOverrider.h"
#include "Engine/UserDefinedEnum.h"

Expand Down Expand Up @@ -1410,6 +1409,22 @@ namespace NS_SLUA {
return 3;
}

int instanceStructClone(lua_State* L) {
LuaStruct* luaStruct = LuaObject::checkValue<LuaStruct*>(L, 1);
auto uss = luaStruct->uss;

uint32 size = luaStruct->size;
uint8* buf = (uint8*)FMemory::Malloc(size);
uss->InitializeStruct(buf);
uss->CopyScriptStruct(buf, luaStruct->buf);

LuaStruct* luaStructCopy = new LuaStruct();
luaStructCopy->Init(buf, size, uss, false);
int ret = LuaObject::push(L, luaStructCopy);
LuaObject::addLink(L,buf);
return ret;
}

int instanceIndexSelf(lua_State* L) {
lua_getmetatable(L,1);

Expand Down Expand Up @@ -1526,14 +1541,6 @@ namespace NS_SLUA {
return LuaObject::push(L, v);
}

int pushUSoftObjectProperty(lua_State *L, FProperty* prop, uint8* parms, NewObjectRecorder* objRecorder) {
auto p = CastField<FSoftObjectProperty>(prop);
ensure(p);
FSoftObjectPtr v = p->GetPropertyValue(parms);
FSoftObjectPtr* softObjectPtr = new FSoftObjectPtr(v);
return LuaObject::push<FSoftObjectPtr>(L, "FSoftObjectPtr", softObjectPtr, UD_AUTOGC | UD_VALUETYPE);
}

void* checkUArrayProperty(lua_State* L,FProperty* prop,uint8* parms,int i,bool bForceCopy) {
auto p = CastField<FArrayProperty>(prop);
ensure(p);
Expand Down Expand Up @@ -2409,7 +2416,6 @@ namespace NS_SLUA {
regPusher(FEnumProperty::StaticClass(), pushEnumProperty);
regPusher(FClassProperty::StaticClass(), pushUClassProperty);
regPusher(FWeakObjectProperty::StaticClass(), pushUWeakProperty);
regPusher(FSoftObjectProperty::StaticClass(), pushUSoftObjectProperty);

regChecker<FIntProperty>();
regChecker<FUInt32Property>();
Expand Down Expand Up @@ -2660,6 +2666,8 @@ namespace NS_SLUA {
lua_setfield(L, -2, "__next");
lua_pushcfunction(L, instanceStructPairs);
lua_setfield(L, -2, "__pairs");
lua_pushcfunction(L, instanceStructClone);
lua_setfield(L, -2, "clone");
return 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ namespace NS_SLUA
{
AsyncLoadedObject& objInfo = asyncLoadedObjects[curIndex];
auto obj = objInfo.obj.Get();
if (obj && !obj->HasAnyFlags(RF_NeedPostLoad))
if (obj && !obj->HasAnyFlags(RF_NeedPostLoad) && !obj->HasAnyFlags(RF_NeedInitialization))
{
// NS_SLUA::Log::Log("LuaOverrider::OnAsyncLoadingFlushUpdate %s", TCHAR_TO_UTF8(*actorInfo.obj->GetFName().ToString()));
UGameInstance* gameInstance = LuaState::getObjectGameInstance(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
#include "luasocket/tcp.h"

#if PLATFORM_WINDOWS
#include "AllowWindowsPlatformTypes.h"
#include "AllowWindowsPlatformAtomics.h"
#include <winsock2.h>
#include "HideWindowsPlatformAtomics.h"
#include "HideWindowsPlatformTypes.h"
#else
#include <sys/ioctl.h>
#endif
Expand Down
Loading

0 comments on commit 6b72315

Please sign in to comment.