-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow GDExtensions to register virtual methods and call them on scripts #87758
Allow GDExtensions to register virtual methods and call them on scripts #87758
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the code to the best of my understanding. Reading the source code the changes makes sense to me. I haven't tested it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool feature! 😊
d699cfd
to
724a471
Compare
@Bromeon Thanks for the review! I've attempted to address your points in my latest push :-) |
Thanks, responded! Will also try to test this with godot-rust this or next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General question: I assume there is no way to require GDScript to implement a certain method, right? As in abstract/pure virtual methods.
To implement such semantics, user code should probably resort to a default implementation that causes an error?
Not via this API. However, the godot-cpp PR adds a
Yep, something like that! In godot-cpp we're mimicking how Godot does it with macros and templates, but other bindings can do whatever makes sense for that particular binding. |
So, I implemented this in Rust, seems to work well! 🦀 Two questions that came up during implementation -- please let me know if that's by design, or I missed something:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing left might be a short TODO
on the conventions (see here), so we avoid proliferating even more styles 😉
None of the points in my last post (super
calls, script-side dynamic dispatch) is a blocker in my opinion -- even in case we eventually plan to change anything in that regard, this PR is a great foundation either way 🙂 Once merged, bindings can follow up with their implementation, too 🚀
Great, thanks!
This is just how virtual methods in Godot work (including in C++ modules): you can't really have a default implementation of a virtual method. The usual pattern is to have a non-virtual method named without an underscore which calls a virtual method named with an underscore. Then if the class wants to do some default behavior if the virtual method isn't implemented (checked via This is, of course, different than how virtual methods work in C++, but it's how the binding layer does them.
Yes, but this sort of makes sense in the context of virtual methods not having default implementations. However, I do think we should add the ability to call But we don't need to account for that in this PR - that's for a different PR in the future. :-) |
724a471
to
be11002
Compare
Thanks!
I've added the TODO's in my latest push :-) |
Thanks for the elaboration, that makes sense. I will then document this accordingly in Rust and see if we can also establish some convention.
I see, so this would work for extensions overriding Godot virtual methods (which are then further overridden by scripts), but not for virtual methods declared by the extension. This might (?) cause some confusion but if it's well documented (including the patterns to work around it), should be OK.
Looks great, thanks a lot! From my side, this PR is good to go 🙂 |
Thanks! |
Thanks! 🤩 Can it be cherry-picked for 4.2.2, maybe? 🙏 |
@limbonaut The GDExtension API generally targets the next minor Godot version (4.3 here), binary compatibility gets very complex otherwise. So this won't be backported. You can however either build Godot yourself from |
Currently, GDExtension classes can implement virtual methods registered in Godot. However, GDExtensions classes can't register their own virtual methods, which scripts attached to them can implement.
This PR adds the necessary changes to the GDExtension interface to allow this!
PR godotengine/godot-cpp#1377 adds support for this to godot-cpp.
Fixes #82267
Production edit: closes godotengine/internal-team-priorities#37