Skip to content

Commit 336ad83

Browse files
committed
Respect the function when calling a function from Lua
In the case of LuaComponent, this allows the user to specify whether the function is to be called on the actor (default behavior) or on the LuaComponent itself.
1 parent 439fffb commit 336ad83

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Source/LuaMachine/Private/LuaState.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,19 @@ void ULuaState::FromLuaValue(FLuaValue& LuaValue, UObject* CallContext, lua_Stat
747747
}
748748
if (CallContext)
749749
{
750-
UObject* FunctionOwner = CallContext;
751-
if (ULuaComponent* LuaComponent = Cast<ULuaComponent>(CallContext))
750+
const UObject* FunctionOwner;
751+
if (LuaValue.Object != nullptr)
752+
{
753+
FunctionOwner = LuaValue.Object;
754+
}
755+
else if (const ULuaComponent* LuaComponent = Cast<ULuaComponent>(CallContext))
752756
{
753757
FunctionOwner = LuaComponent->GetOwner();
754758
}
759+
else
760+
{
761+
FunctionOwner = CallContext;
762+
}
755763

756764
if (FunctionOwner)
757765
{
@@ -2985,11 +2993,19 @@ void ULuaState::SetupAndAssignUserDataMetatable(UObject * Context, TMap<FString,
29852993
// first check for UFunction
29862994
if (Pair.Value.Type == ELuaValueType::UFunction)
29872995
{
2988-
UObject* FunctionOwner = Context;
2989-
if (ULuaComponent* LuaComponent = Cast<ULuaComponent>(Context))
2996+
const UObject* FunctionOwner;
2997+
if (Pair.Value.Object != nullptr)
2998+
{
2999+
FunctionOwner = Pair.Value.Object;
3000+
}
3001+
else if (const ULuaComponent* LuaComponent = Cast<ULuaComponent>(Context))
29903002
{
29913003
FunctionOwner = LuaComponent->GetOwner();
29923004
}
3005+
else
3006+
{
3007+
FunctionOwner = Context;
3008+
}
29933009

29943010
if (FunctionOwner)
29953011
{

0 commit comments

Comments
 (0)