diff --git a/Plugins/slua_unreal/Source/slua_unreal/Private/LuaBase.cpp b/Plugins/slua_unreal/Source/slua_unreal/Private/LuaBase.cpp index 91a9c2b4..0ceff337 100644 --- a/Plugins/slua_unreal/Source/slua_unreal/Private/LuaBase.cpp +++ b/Plugins/slua_unreal/Source/slua_unreal/Private/LuaBase.cpp @@ -44,7 +44,7 @@ namespace NS_SLUA { NS_SLUA::LuaVar lfunc = luaSelfTable.getFromTable((const char*)TCHAR_TO_UTF8(*func->GetName()), true); if (!lfunc.isValid()) return false; - return lfunc.callByUFunction(func, (uint8*)params, &luaSelfTable); + return lfunc.callByUFunction(func, (uint8*)params, nullptr, nullptr, &luaSelfTable); } // Called every frame @@ -246,7 +246,7 @@ namespace NS_SLUA { LuaVar& luaSelfTable = lb->luaSelfTable; NS_SLUA::LuaVar lfunc = luaSelfTable.getFromTable(func->GetName(), true); if (lfunc.isValid()) { - lfunc.callByUFunction(func, (uint8*)params, &luaSelfTable, Stack.OutParms); + lfunc.callByUFunction(func, (uint8*)params, Stack.OutParms, nullptr, &luaSelfTable); *(bool*)RESULT_PARAM = true; } else { diff --git a/Plugins/slua_unreal/Source/slua_unreal/Private/LuaVar.cpp b/Plugins/slua_unreal/Source/slua_unreal/Private/LuaVar.cpp index fa934e0d..730271f7 100644 --- a/Plugins/slua_unreal/Source/slua_unreal/Private/LuaVar.cpp +++ b/Plugins/slua_unreal/Source/slua_unreal/Private/LuaVar.cpp @@ -587,7 +587,7 @@ namespace NS_SLUA { return 0; } - bool LuaVar::callByUFunction(UFunction* func,uint8* parms, LuaVar* pSelf, FOutParmRec* OutParms) { + bool LuaVar::callByUFunction(UFunction* func,uint8* parms,FOutParmRec *outParams,RESULT_DECL,LuaVar* pSelf) { if(!func) return false; @@ -640,6 +640,9 @@ namespace NS_SLUA { auto checkder = prop?LuaObject::getChecker(prop):nullptr; if (checkder) { (*checkder)(L, prop, parms+prop->GetOffset_ForInternal(), lua_absindex(L, -remain)); + if (RESULT_PARAM) { + prop->CopyCompleteValue(RESULT_PARAM, prop->ContainerPtrToValuePtr(parms)); + } } remain--; } @@ -648,16 +651,18 @@ namespace NS_SLUA { for (TFieldIterator it(func); remain >0 && it && (it->PropertyFlags&CPF_Parm); ++it) { UProperty* prop = *it; uint64 propflag = prop->GetPropertyFlags(); - if (IsRealOutParam(propflag)) - { - auto checkder = prop ? LuaObject::getChecker(prop) : nullptr; - uint8* outPamams = OutParms ? OutParms->PropAddr : parms + prop->GetOffset_ForInternal(); - if (checkder) { - (*checkder)(L, prop, outPamams, lua_absindex(L, -remain)); - } - if(OutParms) OutParms = OutParms->NextOutParm; - remain--; - } + if (IsRealOutParam(propflag)) { + auto checker = LuaObject::getChecker(prop); + FOutParmRec* out = outParams; + while (out && out->Property != prop) { + out = out->NextOutParm; + } + uint8* outParam = out ? out->PropAddr : parms + prop->GetOffset_ForInternal(); + if (checker) { + (*checker)(L, prop, outParam, lua_absindex(L, -remain)); + } + remain--; + } } // pop returned value lua_pop(L, retCount); diff --git a/Plugins/slua_unreal/Source/slua_unreal/Public/LuaObject.h b/Plugins/slua_unreal/Source/slua_unreal/Public/LuaObject.h index 946c04a8..83d66fb0 100644 --- a/Plugins/slua_unreal/Source/slua_unreal/Public/LuaObject.h +++ b/Plugins/slua_unreal/Source/slua_unreal/Public/LuaObject.h @@ -369,8 +369,7 @@ namespace NS_SLUA { // return the pointer of class, otherwise return nullptr template static T* checkUD(lua_State* L,int p,bool checkfree=true) { - if (lua_isnil(L, p)) - { + if (lua_isnoneornil(L, p)) { return nullptr; } diff --git a/Plugins/slua_unreal/Source/slua_unreal/Public/LuaVar.h b/Plugins/slua_unreal/Source/slua_unreal/Public/LuaVar.h index b1154fc1..62e6397b 100644 --- a/Plugins/slua_unreal/Source/slua_unreal/Public/LuaVar.h +++ b/Plugins/slua_unreal/Source/slua_unreal/Public/LuaVar.h @@ -239,7 +239,7 @@ namespace NS_SLUA { } bool toProperty(UProperty* p,uint8* ptr); - bool callByUFunction(UFunction* ufunc,uint8* parms,LuaVar* pSelf = nullptr,FOutParmRec* OutParms = nullptr); + bool callByUFunction(UFunction* ufunc,uint8* parms,struct FOutParmRec *outParams=nullptr,RESULT_DECL=nullptr,LuaVar* pSelf=nullptr); // get associate state lua_State* getState() const;