Skip to content

Add Actor.GetComponent(type) and align Actor.GetBehaviour(type) API#778

Open
Gopmyc wants to merge 2 commits intoOverload-Technologies:mainfrom
Gopmyc:777
Open

Add Actor.GetComponent(type) and align Actor.GetBehaviour(type) API#778
Gopmyc wants to merge 2 commits intoOverload-Technologies:mainfrom
Gopmyc:777

Conversation

@Gopmyc
Copy link
Copy Markdown
Contributor

@Gopmyc Gopmyc commented Apr 24, 2026

Description

This PR adds a generic Actor:GetComponent(type) binding to the Lua API and updates the Lua Actor stubs accordingly.

Changes included:

  • Added Actor:GetComponent(type) in Lua bindings (LuaActorBindings.cpp).
  • Implemented a type-to-resolver registry for cleaner and maintainable component lookup.
  • Kept behavior strict: unknown component type returns nil.
  • Aligned GetBehaviour parameter naming to type in bindings and Lua stubs for API consistency.
  • Updated Resources/Engine/Lua/Scene/Actor.lua to expose:
    • Actor:GetComponent(type)
    • Actor:GetBehaviour(type)

Related Issue(s)

Fixes #777

Review Guidance

Please focus review on:

  • Type-based component lookup behavior in Actor:GetComponent(type).
  • Returned value semantics (nil when type is unknown or missing).
  • API consistency between C++ bindings and Lua stubs.

Screenshots/GIFs

N/A

AI Usage Disclosure

Generated new code / Documentation (I did the refactoring)

Checklist

  • My code follows the project's code style guidelines
  • When applicable, I have commented my code, particularly in hard-to-understand areas
  • When applicable, I have updated the documentation accordingly
  • My changes don't generate new warnings or errors
  • I have reviewed and take responsibility for all code in this PR (including any AI-assisted contributions)

@Gopmyc Gopmyc marked this pull request as ready for review April 24, 2026 18:10
@adriengivry
Copy link
Copy Markdown
Member

Not exactly what I had in mind.

By type I didn't mean a string, but a type (i.e. table name).

For example, in Transform.lua:

---@meta

--- Represents the 3D transformations applied to an actor
---@class Transform : Component
Transform = {}

That should allow us to do something like that in a script:

function MyScript:OnStart()
    self.owner:GetComponent(Transform)
end

Since Transform is a valid auto-completable type (thanks to the LSP), it would make it very convenient and safe (prevent typos etc...).

Not sure if it's even possible, but we should definitely investigate.

@Gopmyc
Copy link
Copy Markdown
Contributor Author

Gopmyc commented Apr 24, 2026

Not exactly what I had in mind.

By type I didn't mean a string, but a type (i.e. table name).

For example, in Transform.lua:

---@meta

--- Represents the 3D transformations applied to an actor
---@class Transform : Component
Transform = {}

That should allow us to do something like that in a script:

function MyScript:OnStart()
    self.owner:GetComponent(Transform)
end

Since Transform is a valid auto-completable type (thanks to the LSP), it would make it very convenient and safe (prevent typos etc...).

Not sure if it's even possible, but we should definitely investigate.

That would mean polluting Lua's global table with lots of elements like Transform, is that really a good idea ?

@adriengivry
Copy link
Copy Markdown
Member

adriengivry commented Apr 24, 2026

@Gopmyc wdym pollute the global table? These user types are already defined in the global table: LuaComponentBindings.cpp and captured by the LSP thank to the LuaLS definitions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add GetComponent(type) and GetBehaviour(type) to the Actor Lua bindings

2 participants