Skip to content

Commit

Permalink
Merge pull request #465 from lilizoey/fix/use-latest-preview-build
Browse files Browse the repository at this point in the history
Fix custom callable no longer working on latest Godot master
  • Loading branch information
Bromeon authored Oct 25, 2023
2 parents 0028a86 + 79ed1bb commit e6debc9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
5 changes: 4 additions & 1 deletion godot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ categories = ["game-engines", "graphics"]
default = []
codegen-fmt = ["godot-ffi/codegen-fmt", "godot-codegen/codegen-fmt"]
codegen-full = ["godot-codegen/codegen-full"]
codegen-lazy-fptrs = ["godot-ffi/codegen-lazy-fptrs", "godot-codegen/codegen-lazy-fptrs"]
codegen-lazy-fptrs = [
"godot-ffi/codegen-lazy-fptrs",
"godot-codegen/codegen-lazy-fptrs",
]
custom-godot = ["godot-ffi/custom-godot", "godot-codegen/custom-godot"]
double-precision = ["godot-codegen/double-precision"]
experimental-godot-api = ["godot-codegen/experimental-godot-api"]
Expand Down
31 changes: 19 additions & 12 deletions godot-core/src/builtin/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ impl Callable {
}
}

#[cfg(since_api = "4.2")]
fn default_callable_custom_info() -> sys::GDExtensionCallableCustomInfo {
sys::GDExtensionCallableCustomInfo {
callable_userdata: ptr::null_mut(),
token: ptr::null_mut(),
object_id: 0,
call_func: None,
is_valid_func: None, // could be customized, but no real use case yet.
free_func: None,
hash_func: None,
equal_func: None,
// Op < is only used in niche scenarios and default is usually good enough, see https://github.com/godotengine/godot/issues/81901.
less_than_func: None,
to_string_func: None,
}
}

/// Create a callable from a Rust function or closure.
///
/// `name` is used for the string representation of the closure, which helps debugging.
Expand Down Expand Up @@ -83,16 +100,10 @@ impl Callable {

let info = sys::GDExtensionCallableCustomInfo {
callable_userdata: Box::into_raw(Box::new(userdata)) as *mut std::ffi::c_void,
token: ptr::null_mut(),
object: ptr::null_mut(),
call_func: Some(rust_callable_call_fn::<F>),
is_valid_func: None, // could be customized, but no real use case yet.
free_func: Some(rust_callable_destroy::<FnWrapper<F>>),
hash_func: None,
equal_func: None,
// Op < is only used in niche scenarios and default is usually good enough, see https://github.com/godotengine/godot/issues/81901.
less_than_func: None,
to_string_func: Some(rust_callable_to_string_named::<F>),
..Self::default_callable_custom_info()
};

Self::from_custom_info(info)
Expand All @@ -110,16 +121,12 @@ impl Callable {

let info = sys::GDExtensionCallableCustomInfo {
callable_userdata: Box::into_raw(Box::new(userdata)) as *mut std::ffi::c_void,
token: ptr::null_mut(),
object: ptr::null_mut(),
call_func: Some(rust_callable_call_custom::<C>),
is_valid_func: None, // could be customized, but no real use case yet.
free_func: Some(rust_callable_destroy::<C>),
hash_func: Some(rust_callable_hash::<C>),
equal_func: Some(rust_callable_equal::<C>),
// Op < is only used in niche scenarios and default is usually good enough, see https://github.com/godotengine/godot/issues/81901.
less_than_func: None,
to_string_func: Some(rust_callable_to_string_display::<C>),
..Self::default_callable_custom_info()
};

Self::from_custom_info(info)
Expand Down

0 comments on commit e6debc9

Please sign in to comment.