Skip to content

Allow GDExtensions to register virtual methods and call them on scripts (godot-cpp support)#1377

Merged
dsnopek merged 1 commit into
godotengine:masterfrom
dsnopek:gdextension-register-virtual-method
Feb 13, 2024
Merged

Allow GDExtensions to register virtual methods and call them on scripts (godot-cpp support)#1377
dsnopek merged 1 commit into
godotengine:masterfrom
dsnopek:gdextension-register-virtual-method

Conversation

@dsnopek

@dsnopek dsnopek commented Jan 30, 2024

Copy link
Copy Markdown
Collaborator

This depends on PR godotengine/godot#87758

It adds APIs compatible with Godot's, including the following macros:

  • GDVIRTUAL*() (like GDVIRTUAL0R(), GDVIRTUAL2C(), etc)
  • GDVIRTUAL_BIND()
  • GDVIRTUAL_CALL()
  • GDVIRTUAL_IS_OVERRIDDEN()
  • ... and all the rest!

It also adds an automated test for this functionality to CI.

NOTE: The tests here will fail until after the Godot PR is merged! However, they are passing for me locally.

Fixes #1199
Fixes #1072
Fixes #910

@dsnopek dsnopek added the enhancement This is an enhancement on the current functionality label Jan 30, 2024
@dsnopek dsnopek added this to the 4.x milestone Jan 30, 2024
@dsnopek
dsnopek requested a review from a team as a code owner January 30, 2024 22:35
@dsnopek
dsnopek force-pushed the gdextension-register-virtual-method branch from da9098a to a969e47 Compare January 30, 2024 22:41
@AThousandShips AThousandShips added the waiting for Godot PRs that can't be merged until an engine PR is merged first label Jan 31, 2024
@Remi123

Remi123 commented Jan 31, 2024

Copy link
Copy Markdown

I've been waiting for this feature for over a year. Thank you so much.

Glad to see an example. 4.3 will be great for plugin.

@dsnopek
dsnopek force-pushed the gdextension-register-virtual-method branch from a969e47 to 8fbb7cf Compare February 12, 2024 19:30

@akien-mga akien-mga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't review in depth, but looks good at a glance. We merged the upstream counterpart so this could be merged now.

@Kehom

Kehom commented Mar 11, 2024

Copy link
Copy Markdown
Contributor

I finally got back to the code I needed this feature. I have noticed that the macros defined in the gdvirtual.gen.inc file begin with StringName _gdvritual_ without explicit namespace usage. This somewhat forces extension code to add using namespace godot.

Is this intended?

EDIT: I attempted to create a custom macro copying the original one but adding the explicit godot::NameString thing. It didn't work. Nevertheless, the macros do work if I add the using namespace godot (which is not exactly something I wanted to do).

@dsnopek

dsnopek commented Mar 11, 2024

Copy link
Copy Markdown
Collaborator Author

Is this intended?

Nope! This is probably just an artifact of those macros starting out as a copy of the same macros from Godot.

@dsnopek

dsnopek commented Mar 11, 2024

Copy link
Copy Markdown
Collaborator Author

@Kehom Can you test if this PR fixes it for you? #1412 Unfortunately, I don't have a project that doesn't use using namespace godot at hand to test if those changes are sufficient

@Kehom

Kehom commented Mar 11, 2024

Copy link
Copy Markdown
Contributor

Thanks for the answer. I think it will be best for me to answer about the fix in the PR itself.

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

Labels

enhancement This is an enhancement on the current functionality waiting for Godot PRs that can't be merged until an engine PR is merged first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Virtual function binding can GDVIRTUAL_BIND and GDVIRTUAL_CALL be added to the lib? cast_to and virtual function confusing behavior

5 participants