Skip to content

Conversation

@micheljung
Copy link

@micheljung micheljung commented Jul 21, 2025

I want to achieve this:

UShipLuaComponent::UShipLuaComponent()
{
  Table.Add("GetActorLocation", FLuaValue::Function(GET_FUNCTION_NAME_CHECKED(UShipLuaComponent, GetActorLocation)));
}

FLuaValue UShipLuaComponent::GetActorLocation() {
  ...
}

And then have this

self.GetActorLocation()

To call the function on the component.

However, this currently calls AShip::GetActorLocation() instead of UShipLuaComponent::GetActorLocation().

This seems to be by design.

The downside is that the owning component now needs to declare Lua-compatible functions, leading to tight coupling.

With the suggested change, the user can instead use FunctionOfObject:

Table.Add("GetActorLocation", FLuaValue::FunctionOfObject(this, GET_FUNCTION_NAME_CHECKED(UShipLuaComponent, GetActorLocation)));

And have the function called on the component instead of the owner. This change is backward-compatible.

@micheljung
Copy link
Author

I think the code is OK, but I'm not yet sure how to get the component instance. With what I'm doing currently, I get NULL for GetOwner().

Let's put this on hold until I figured this out.

@micheljung micheljung changed the title Respect the function when calling a function from Lua DRAFT: Respect the function when calling a function from Lua Jul 21, 2025
@micheljung micheljung marked this pull request as draft July 21, 2025 20:48
@micheljung micheljung changed the title DRAFT: Respect the function when calling a function from Lua Respect the function when calling a function from Lua Jul 21, 2025
This makes it easier for contributors.
I'm not sure what the current max line length is, but I guess it's 140.

Also, the current code isn't always properly formatted, this should be
fixed in a separate commit.
@micheljung micheljung force-pushed the mj/lua-call-function-owner branch from 336ad83 to 79c8acd Compare July 22, 2025 10:35
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.
@micheljung micheljung force-pushed the mj/lua-call-function-owner branch from 79c8acd to 9647047 Compare July 22, 2025 10:40
@micheljung micheljung changed the title Respect the function when calling a function from Lua Respect the function owner when calling a function from Lua Aug 3, 2025
@micheljung micheljung marked this pull request as ready for review August 3, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant