Skip to content
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

Use GDExtensionCallableCustomInfo2 instead of deprecated GDExtensionCallableCustomInfo. #952

Merged
merged 2 commits into from
Nov 23, 2024

Conversation

Yarwin
Copy link
Contributor

@Yarwin Yarwin commented Nov 23, 2024

The only difference between old and new GDExtensionCallableCustomInfo is an addition of get_argument_count_func. In godot-cpp implementation the only way to provide an argument count is overriding the method in a question.

For now I'm leaving the nullptr – consider implementing builder pattern for the Callable (Callable::from_…ex(…).arg_count(n).done()) if the need to do so arise (would require changes to userdata stored with the callable).

One could provide blanket implementation, but IMO it would be only more confusing. Gdext checks if given function is present https://github.com/godotengine/godot/blob/0c45ace151f25de2ca54fe7a46b6f077be32ba6f/core/extension/gdextension_interface.cpp#L149, executes it and returns the result if it is valid (r_is_valid) – otherwise it returns "0" (in other words, the default implementation is already provided by the engine itself).

@Yarwin Yarwin force-pushed the use-callable-custom-info-2 branch from 277863e to 0af2f6d Compare November 23, 2024 13:01
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-952

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

Comment on lines 19 to 21
#[cfg(before_api = "4.3")]
#[cfg(since_api = "4.2")]
type GDExtensionCallableCustomInfo = sys::GDExtensionCallableCustomInfo;
Copy link
Member

Choose a reason for hiding this comment

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

You can use all(...) here 🙂

Suggested change
#[cfg(before_api = "4.3")]
#[cfg(since_api = "4.2")]
type GDExtensionCallableCustomInfo = sys::GDExtensionCallableCustomInfo;
#[cfg(all(since_api = "4.2", before_api = "4.3"))]
type GDExtensionCallableCustomInfo = sys::GDExtensionCallableCustomInfo;

Comment on lines 22 to 23
#[cfg(since_api = "4.3")]
type GDExtensionCallableCustomInfo = sys::GDExtensionCallableCustomInfo2;
Copy link
Member

Choose a reason for hiding this comment

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

The naming is a bit confusing -- the use sites look like sys:: was forgotten and the code is referring to sys::GDExtensionCallableCustomInfo.

Maybe just like this, to make clear it's not a typedef exported by the GDExtension API itself?

Suggested change
#[cfg(since_api = "4.3")]
type GDExtensionCallableCustomInfo = sys::GDExtensionCallableCustomInfo2;
#[cfg(since_api = "4.3")]
type CallableCustomInfo = sys::GDExtensionCallableCustomInfo2;

@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: register Register classes, functions and other symbols to GDScript labels Nov 23, 2024
…onCallableCustomInfo`.

======

The only difference between old and new `GDExtensionCallableCustomInfo` is an addition of `get_argument_count_func`. In godot-cpp implementation the only way to get this count is overriding method in the question; For now we are leaving nullptr – consider implementing builder pattern for the Callable (`Callable::from_…ex(…).arg_count(n).done()`) if the need to do so arise.
@Yarwin Yarwin force-pushed the use-callable-custom-info-2 branch from 0af2f6d to 6f21759 Compare November 23, 2024 15:42
@Bromeon Bromeon added this pull request to the merge queue Nov 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 23, 2024
@Bromeon Bromeon enabled auto-merge November 23, 2024 16:07
@Bromeon Bromeon added this pull request to the merge queue Nov 23, 2024
Merged via the queue into godot-rust:master with commit f8a0939 Nov 23, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: register Register classes, functions and other symbols to GDScript quality-of-life No new functionality, but improves ergonomics/internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants