Skip to content

Commit

Permalink
bug fix for passing non-const reference parameters from Blueprint to …
Browse files Browse the repository at this point in the history
…Lua.
  • Loading branch information
rowechien committed Mar 28, 2020
1 parent b6ab88f commit 556a5cd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
31 changes: 20 additions & 11 deletions Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,19 +1354,15 @@ int32 FFunctionDesc::PostCall(lua_State *L, int32 NumParams, int32 FirstParamInd
/**
* Get OutParmRec for a non-const reference property
*/
static FOutParmRec* GetNonConstOutParmRec(FOutParmRec *OutParam, UProperty *OutProperty)
static FOutParmRec* FindOutParmRec(FOutParmRec *OutParam, UProperty *OutProperty)
{
if (!OutProperty->HasAnyPropertyFlags(CPF_ConstParm))
while (OutParam)
{
FOutParmRec *Out = OutParam;
while (Out)
if (OutParam->Property == OutProperty)
{
if (Out->Property == OutProperty)
{
return Out;
}
Out = Out->NextOutParm;
return OutParam;
}
OutParam = OutParam->NextOutParm;
}
return nullptr;
}
Expand All @@ -1377,12 +1373,25 @@ static FOutParmRec* GetNonConstOutParmRec(FOutParmRec *OutParam, UProperty *OutP
bool FFunctionDesc::CallLuaInternal(lua_State *L, void *InParams, FOutParmRec *OutParams, void *RetValueAddress) const
{
// prepare parameters for Lua function
FOutParmRec *OutParam = OutParams;
for (const FPropertyDesc *Property : Properties)
{
if (Property->IsReturnParameter())
{
continue;
}

if (Property->IsConstOutParameter())
{
OutParam = FindOutParmRec(OutParam, Property->GetProperty());
if (OutParam)
{
Property->GetValueInternal(L, OutParam->PropAddr, false);
OutParam = OutParam->NextOutParm;
continue;
}
}

Property->GetValue(L, InParams, false);
}

Expand All @@ -1395,11 +1404,11 @@ bool FFunctionDesc::CallLuaInternal(lua_State *L, void *InParams, FOutParmRec *O
}

int32 OutPropertyIndex = -NumResult;
FOutParmRec *OutParam = OutParams;
OutParam = OutParams;
for (int32 i = 0; i < OutPropertyIndices.Num(); ++i)
{
FPropertyDesc *OutProperty = Properties[OutPropertyIndices[i]];
OutParam = GetNonConstOutParmRec(OutParam, OutProperty->GetProperty());
OutParam = FindOutParmRec(OutParam, OutProperty->GetProperty());
check(OutParam);
int32 Type = lua_type(L, OutPropertyIndex);
if (Type == LUA_TNIL)
Expand Down
16 changes: 15 additions & 1 deletion Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,21 @@ class FPropertyDesc : public UnLua::ITypeInterface
FORCEINLINE bool IsValid() const { return Property != nullptr; }

/**
* Test if this property is an out parameter. out parameter means return parameter or non-const parameter
* Test if this property is a const reference parameter.
*
* @return - true if the property is a const reference parameter, false otherwise
*/
FORCEINLINE bool IsConstOutParameter() const { return Property->HasAllPropertyFlags(CPF_OutParm | CPF_ConstParm); }

/**
* Test if this property is a non-const reference parameter.
*
* @return - true if the property is a non-const reference parameter, false otherwise
*/
FORCEINLINE bool IsNonConstOutParameter() const { return Property->HasAnyPropertyFlags(CPF_OutParm) && !Property->HasAnyPropertyFlags(CPF_ConstParm); }

/**
* Test if this property is an out parameter. out parameter means return parameter or non-const reference parameter
*
* @return - true if the property is an out parameter, false otherwise
*/
Expand Down

0 comments on commit 556a5cd

Please sign in to comment.