Skip to content

Commit 0af2f6d

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 0af2f6d

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

godot-core/src/builtin/callable.rs

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

19+
#[cfg(before_api = "4.3")]
20+
#[cfg(since_api = "4.2")]
21+
type GDExtensionCallableCustomInfo = sys::GDExtensionCallableCustomInfo;
22+
#[cfg(since_api = "4.3")]
23+
type GDExtensionCallableCustomInfo = sys::GDExtensionCallableCustomInfo2;
24+
1925
/// A `Callable` represents a function in Godot.
2026
///
2127
/// Usually a callable is a reference to an `Object` and a method name, this is a standard callable. But can
@@ -61,8 +67,8 @@ impl Callable {
6167
}
6268

6369
#[cfg(since_api = "4.2")]
64-
fn default_callable_custom_info() -> sys::GDExtensionCallableCustomInfo {
65-
sys::GDExtensionCallableCustomInfo {
70+
fn default_callable_custom_info() -> GDExtensionCallableCustomInfo {
71+
GDExtensionCallableCustomInfo {
6672
callable_userdata: ptr::null_mut(),
6773
token: ptr::null_mut(),
6874
object_id: 0,
@@ -74,6 +80,8 @@ impl Callable {
7480
// Op < is only used in niche scenarios and default is usually good enough, see https://github.com/godotengine/godot/issues/81901.
7581
less_than_func: None,
7682
to_string_func: None,
83+
#[cfg(since_api = "4.3")]
84+
get_argument_count_func: None,
7785
}
7886
}
7987

@@ -105,7 +113,7 @@ impl Callable {
105113
},
106114
};
107115

108-
let info = sys::GDExtensionCallableCustomInfo {
116+
let info = GDExtensionCallableCustomInfo {
109117
callable_userdata: Box::into_raw(Box::new(userdata)) as *mut std::ffi::c_void,
110118
call_func: Some(rust_callable_call_fn::<F>),
111119
free_func: Some(rust_callable_destroy::<FnWrapper<F>>),
@@ -126,7 +134,7 @@ impl Callable {
126134
// - a type-erased workaround for PartialEq supertrait (which has a `Self` type parameter and thus is not object-safe)
127135
let userdata = CallableUserdata { inner: callable };
128136

129-
let info = sys::GDExtensionCallableCustomInfo {
137+
let info = GDExtensionCallableCustomInfo {
130138
callable_userdata: Box::into_raw(Box::new(userdata)) as *mut std::ffi::c_void,
131139
call_func: Some(rust_callable_call_custom::<C>),
132140
free_func: Some(rust_callable_destroy::<C>),
@@ -140,11 +148,18 @@ impl Callable {
140148
}
141149

142150
#[cfg(since_api = "4.2")]
143-
fn from_custom_info(mut info: sys::GDExtensionCallableCustomInfo) -> Callable {
151+
fn from_custom_info(mut info: GDExtensionCallableCustomInfo) -> Callable {
144152
// SAFETY: callable_custom_create() is a valid way of creating callables.
145153
unsafe {
146154
Callable::new_with_uninit(|type_ptr| {
147-
sys::interface_fn!(callable_custom_create)(type_ptr, ptr::addr_of_mut!(info))
155+
#[cfg(before_api = "4.3")]
156+
{
157+
sys::interface_fn!(callable_custom_create)(type_ptr, ptr::addr_of_mut!(info))
158+
}
159+
#[cfg(since_api = "4.3")]
160+
{
161+
sys::interface_fn!(callable_custom_create2)(type_ptr, ptr::addr_of_mut!(info))
162+
}
148163
})
149164
}
150165
}

0 commit comments

Comments
 (0)