Skip to content

Commit 6f21759

Browse files
committed
Use GDExtensionCallableCustomInfo2 instead of deprecated GDExtensionCallableCustomInfo.
====== 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.
1 parent 8beef9d commit 6f21759

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

godot-core/src/builtin/callable.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ use crate::obj::{Gd, GodotClass, InstanceId};
1616
use std::{fmt, ptr};
1717
use sys::{ffi_methods, GodotFfi};
1818

19+
#[cfg(all(since_api = "4.2", before_api = "4.3"))]
20+
type CallableCustomInfo = sys::GDExtensionCallableCustomInfo;
21+
#[cfg(since_api = "4.3")]
22+
type CallableCustomInfo = sys::GDExtensionCallableCustomInfo2;
23+
1924
/// A `Callable` represents a function in Godot.
2025
///
2126
/// Usually a callable is a reference to an `Object` and a method name, this is a standard callable. But can
@@ -61,8 +66,8 @@ impl Callable {
6166
}
6267

6368
#[cfg(since_api = "4.2")]
64-
fn default_callable_custom_info() -> sys::GDExtensionCallableCustomInfo {
65-
sys::GDExtensionCallableCustomInfo {
69+
fn default_callable_custom_info() -> CallableCustomInfo {
70+
CallableCustomInfo {
6671
callable_userdata: ptr::null_mut(),
6772
token: ptr::null_mut(),
6873
object_id: 0,
@@ -74,6 +79,8 @@ impl Callable {
7479
// Op < is only used in niche scenarios and default is usually good enough, see https://github.com/godotengine/godot/issues/81901.
7580
less_than_func: None,
7681
to_string_func: None,
82+
#[cfg(since_api = "4.3")]
83+
get_argument_count_func: None,
7784
}
7885
}
7986

@@ -105,7 +112,7 @@ impl Callable {
105112
},
106113
};
107114

108-
let info = sys::GDExtensionCallableCustomInfo {
115+
let info = CallableCustomInfo {
109116
callable_userdata: Box::into_raw(Box::new(userdata)) as *mut std::ffi::c_void,
110117
call_func: Some(rust_callable_call_fn::<F>),
111118
free_func: Some(rust_callable_destroy::<FnWrapper<F>>),
@@ -126,7 +133,7 @@ impl Callable {
126133
// - a type-erased workaround for PartialEq supertrait (which has a `Self` type parameter and thus is not object-safe)
127134
let userdata = CallableUserdata { inner: callable };
128135

129-
let info = sys::GDExtensionCallableCustomInfo {
136+
let info = CallableCustomInfo {
130137
callable_userdata: Box::into_raw(Box::new(userdata)) as *mut std::ffi::c_void,
131138
call_func: Some(rust_callable_call_custom::<C>),
132139
free_func: Some(rust_callable_destroy::<C>),
@@ -140,11 +147,18 @@ impl Callable {
140147
}
141148

142149
#[cfg(since_api = "4.2")]
143-
fn from_custom_info(mut info: sys::GDExtensionCallableCustomInfo) -> Callable {
150+
fn from_custom_info(mut info: CallableCustomInfo) -> Callable {
144151
// SAFETY: callable_custom_create() is a valid way of creating callables.
145152
unsafe {
146153
Callable::new_with_uninit(|type_ptr| {
147-
sys::interface_fn!(callable_custom_create)(type_ptr, ptr::addr_of_mut!(info))
154+
#[cfg(before_api = "4.3")]
155+
{
156+
sys::interface_fn!(callable_custom_create)(type_ptr, ptr::addr_of_mut!(info))
157+
}
158+
#[cfg(since_api = "4.3")]
159+
{
160+
sys::interface_fn!(callable_custom_create2)(type_ptr, ptr::addr_of_mut!(info))
161+
}
148162
})
149163
}
150164
}

0 commit comments

Comments
 (0)