Skip to content

Commit

Permalink
Merge pull request #350 from zjhongxian/master
Browse files Browse the repository at this point in the history
多个bug修复,并且LuaVar::callByUFunction添加RESULT_DECL参数
  • Loading branch information
pangweiwei authored Jul 31, 2020
2 parents 898893a + 8440aaa commit 9177ff8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Plugins/slua_unreal/Source/slua_unreal/Private/LuaBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace NS_SLUA {
NS_SLUA::LuaVar lfunc = luaSelfTable.getFromTable<NS_SLUA::LuaVar>((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
Expand Down Expand Up @@ -246,7 +246,7 @@ namespace NS_SLUA {
LuaVar& luaSelfTable = lb->luaSelfTable;
NS_SLUA::LuaVar lfunc = luaSelfTable.getFromTable<NS_SLUA::LuaVar>(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 {
Expand Down
27 changes: 16 additions & 11 deletions Plugins/slua_unreal/Source/slua_unreal/Private/LuaVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<uint8>(parms));
}
}
remain--;
}
Expand All @@ -648,16 +651,18 @@ namespace NS_SLUA {
for (TFieldIterator<UProperty> 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);
Expand Down
3 changes: 1 addition & 2 deletions Plugins/slua_unreal/Source/slua_unreal/Public/LuaObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ namespace NS_SLUA {
// return the pointer of class, otherwise return nullptr
template<typename T>
static T* checkUD(lua_State* L,int p,bool checkfree=true) {
if (lua_isnil(L, p))
{
if (lua_isnoneornil(L, p)) {
return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion Plugins/slua_unreal/Source/slua_unreal/Public/LuaVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9177ff8

Please sign in to comment.