Skip to content

Commit

Permalink
bug fix for calling RPC functions with container parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rowechien committed Mar 14, 2020
1 parent cc10354 commit fbd1158
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
61 changes: 34 additions & 27 deletions Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FIntegerPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
NumericProperty->SetIntPropertyValue(ValuePtr, (uint64)lua_tointeger(L, IndexInStack));
return false;
Expand All @@ -67,7 +67,7 @@ class FFloatPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
NumericProperty->SetFloatingPointPropertyValue(ValuePtr, lua_tonumber(L, IndexInStack));
return false;
Expand Down Expand Up @@ -98,7 +98,7 @@ class FEnumPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
EnumProperty->GetUnderlyingProperty()->SetIntPropertyValue(ValuePtr, lua_tointeger(L, IndexInStack));
return false;
Expand All @@ -118,7 +118,7 @@ class FBoolPropertyDesc : public FPropertyDesc
lua_pushboolean(L, BoolProperty->GetPropertyValue(ValuePtr));
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
BoolProperty->SetPropertyValue(ValuePtr, lua_toboolean(L, IndexInStack) != 0);
return false;
Expand Down Expand Up @@ -193,7 +193,7 @@ class FObjectPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
if (MetaClass)
{
Expand Down Expand Up @@ -240,7 +240,7 @@ class FInterfacePropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
FScriptInterface *Interface = (FScriptInterface*)ValuePtr;
UObject *Value = UnLua::GetUObject(L, IndexInStack);
Expand Down Expand Up @@ -270,7 +270,7 @@ class FNamePropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
NameProperty->SetPropertyValue(ValuePtr, FName(lua_tostring(L, IndexInStack)));
return true;
Expand All @@ -297,7 +297,7 @@ class FStringPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
StringProperty->SetPropertyValue(ValuePtr, UTF8_TO_TCHAR(lua_tostring(L, IndexInStack)));
return true;
Expand All @@ -324,7 +324,7 @@ class FTextPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
TextProperty->SetPropertyValue(ValuePtr, FText::FromString(UTF8_TO_TCHAR(lua_tostring(L, IndexInStack))));
return true;
Expand Down Expand Up @@ -390,7 +390,7 @@ class FArrayPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
int32 Type = lua_type(L, IndexInStack);
if (Type == LUA_TTABLE)
Expand All @@ -405,7 +405,7 @@ class FArrayPropertyDesc : public FPropertyDesc
FScriptArray *Src = (FScriptArray*)GetScriptContainer(L, IndexInStack);
if (Src)
{
if (!bCopyValue && !bRemote && Property->HasAnyPropertyFlags(CPF_OutParm))
if (!bCopyValue && Property->HasAnyPropertyFlags(CPF_OutParm))
{
FMemory::Memcpy(ValuePtr, Src, sizeof(FScriptArray)); // shallow copy
return false;
Expand All @@ -417,7 +417,7 @@ class FArrayPropertyDesc : public FPropertyDesc
}
}
}
return bCopyValue;
return true;
}

static bool FillArray(lua_State *L, void *Userdata)
Expand Down Expand Up @@ -493,7 +493,7 @@ class FMapPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
int32 Type = lua_type(L, IndexInStack);
if (Type == LUA_TTABLE)
Expand All @@ -508,7 +508,7 @@ class FMapPropertyDesc : public FPropertyDesc
FLuaMap *LuaMap = (FLuaMap*)GetCppInstanceFast(L, IndexInStack);
if (LuaMap)
{
if (!bCopyValue && !bRemote && Property->HasAnyPropertyFlags(CPF_OutParm))
if (!bCopyValue && Property->HasAnyPropertyFlags(CPF_OutParm))
{
FMemory::Memcpy(ValuePtr, LuaMap->Map, sizeof(FScriptMap)); // shallow copy
return false;
Expand All @@ -519,7 +519,7 @@ class FMapPropertyDesc : public FPropertyDesc
}
}
}
return bCopyValue;
return true;
}

static bool FillMap(lua_State *L, void *Userdata)
Expand Down Expand Up @@ -598,7 +598,7 @@ class FSetPropertyDesc : public FPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
int32 Type = lua_type(L, IndexInStack);
if (Type == LUA_TTABLE)
Expand All @@ -613,7 +613,7 @@ class FSetPropertyDesc : public FPropertyDesc
FLuaSet *LuaSet = (FLuaSet*)GetCppInstanceFast(L, IndexInStack);
if (LuaSet)
{
if (!bCopyValue && !bRemote && Property->HasAnyPropertyFlags(CPF_OutParm))
if (!bCopyValue && Property->HasAnyPropertyFlags(CPF_OutParm))
{
FMemory::Memcpy(ValuePtr, LuaSet->Set, sizeof(FScriptSet)); // shallow copy
return false;
Expand All @@ -624,7 +624,7 @@ class FSetPropertyDesc : public FPropertyDesc
}
}
}
return bCopyValue;
return true;
}

static bool FillSet(lua_State *L, void *Userdata)
Expand Down Expand Up @@ -718,7 +718,7 @@ class FScriptStructPropertyDesc : public FStructPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
#if UE_BUILD_DEBUG
int32 Type = lua_type(L, IndexInStack);
Expand Down Expand Up @@ -751,7 +751,7 @@ class FScriptStructPropertyDesc : public FStructPropertyDesc
void *Value = GetCppInstanceFast(L, IndexInStack);
if (Value)
{
if (!bCopyValue && !bRemote && Property->HasAnyPropertyFlags(CPF_OutParm))
if (!bCopyValue && Property->HasAnyPropertyFlags(CPF_OutParm))
{
FMemory::Memcpy(ValuePtr, Value, StructSize); // shallow copy
return false;
Expand All @@ -761,7 +761,7 @@ class FScriptStructPropertyDesc : public FStructPropertyDesc
StructProperty->CopySingleValue(ValuePtr, Value);
}
}
return bCopyValue;
return true;
}

private:
Expand Down Expand Up @@ -792,7 +792,7 @@ class FDelegatePropertyDesc : public FStructPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
UObject *Object = nullptr;
const void *CallbackFunction = nullptr;
Expand Down Expand Up @@ -841,7 +841,7 @@ class TMulticastDelegatePropertyDesc : public FStructPropertyDesc
}
}

virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue, bool bRemote) const override
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack, bool bCopyValue) const override
{
UObject *Object = nullptr;
const void *CallbackFunction = nullptr;
Expand Down Expand Up @@ -1152,7 +1152,7 @@ int32 FFunctionDesc::CallUE(lua_State *L, int32 NumParams, void *Userdata)
bool bRemote = false;
#endif

void *Params = PreCall(L, NumParams, FirstParamIndex, Userdata, bRemote); // prepare values of properties
void *Params = PreCall(L, NumParams, FirstParamIndex, Userdata); // prepare values of properties

UFunction *FinalFunction = Function;
if (bInterfaceFunc)
Expand Down Expand Up @@ -1200,7 +1200,14 @@ int32 FFunctionDesc::CallUE(lua_State *L, int32 NumParams, void *Userdata)
else
#endif
{
Object->UObject::ProcessEvent(FinalFunction, Params);
if (bRemote)
{
Object->CallRemoteFunction(FinalFunction, Params, nullptr, nullptr);
}
else
{
Object->UObject::ProcessEvent(FinalFunction, Params);
}
}

int32 NumReturnValues = PostCall(L, NumParams, FirstParamIndex, Params); // push 'out' properties to Lua stack
Expand Down Expand Up @@ -1243,7 +1250,7 @@ void FFunctionDesc::BroadcastMulticastDelegate(lua_State *L, int32 NumParams, in
/**
* Prepare values of properties for the UFunction
*/
void* FFunctionDesc::PreCall(lua_State *L, int32 NumParams, int32 FirstParamIndex, void *Userdata, bool bRemote)
void* FFunctionDesc::PreCall(lua_State *L, int32 NumParams, int32 FirstParamIndex, void *Userdata)
{
#if ENABLE_PERSISTENT_PARAM_BUFFER
void *Params = Buffer;
Expand Down Expand Up @@ -1273,7 +1280,7 @@ void* FFunctionDesc::PreCall(lua_State *L, int32 NumParams, int32 FirstParamInde
}
if (ParamIndex < NumParams)
{
CleanupFlags[i] = Property->SetValue(L, Params, FirstParamIndex + ParamIndex, false, bRemote);
CleanupFlags[i] = Property->SetValue(L, Params, FirstParamIndex + ParamIndex, false);
}
else if (!Property->IsOutParameter())
{
Expand Down
8 changes: 4 additions & 4 deletions Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ class FPropertyDesc : public UnLua::ITypeInterface
* @param bCopyValue - whether to create a copy for the value
* @return - true if 'ContainerPtr' should be cleaned up by 'DestroyValue_InContainer', false otherwise
*/
FORCEINLINE bool SetValue(lua_State *L, void *ContainerPtr, int32 IndexInStack = -1, bool bCopyValue = true, bool bRemote = false) const
FORCEINLINE bool SetValue(lua_State *L, void *ContainerPtr, int32 IndexInStack = -1, bool bCopyValue = true) const
{
return SetValueInternal(L, Property->ContainerPtrToValuePtr<void>(ContainerPtr), IndexInStack, bCopyValue, bRemote);
return SetValueInternal(L, Property->ContainerPtrToValuePtr<void>(ContainerPtr), IndexInStack, bCopyValue);
}

virtual void GetValueInternal(lua_State *L, const void *ValuePtr, bool bCreateCopy) const = 0;
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack = -1, bool bCopyValue = true, bool bRemote = false) const = 0;
virtual bool SetValueInternal(lua_State *L, void *ValuePtr, int32 IndexInStack = -1, bool bCopyValue = true) const = 0;

/**
* Copy an element at the given Lua index to the value of this property
Expand Down Expand Up @@ -269,7 +269,7 @@ class FFunctionDesc
void BroadcastMulticastDelegate(lua_State *L, int32 NumParams, int32 FirstParamIndex, FMulticastScriptDelegate *ScriptDelegate);

private:
void* PreCall(lua_State *L, int32 NumParams, int32 FirstParamIndex, void *Userdata = nullptr, bool bRemote = false);
void* PreCall(lua_State *L, int32 NumParams, int32 FirstParamIndex, void *Userdata = nullptr);
int32 PostCall(lua_State *L, int32 NumParams, int32 FirstParamIndex, void *Params);

bool CallLuaInternal(lua_State *L, void *InParams, FOutParmRec *OutParams, void *RetValueAddress) const;
Expand Down

0 comments on commit fbd1158

Please sign in to comment.