Skip to content

Commit 7b8823d

Browse files
committed
Callable: rename arg_len() etc. to their original Godot names
Also consistently return usize (0 lower bound) for get_bound_arguments_count().
1 parent ee4f2ed commit 7b8823d

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

godot-core/src/builtin/callable.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ impl Callable {
307307
/// _Godot equivalent: `get_method`_
308308
///
309309
/// [godot#73052]: https://github.com/godotengine/godot/issues/73052
310+
#[doc(alias = "get_method")]
310311
pub fn method_name(&self) -> Option<StringName> {
311312
let method_name = self.as_inner().get_method();
312313
if method_name.is_empty() {
@@ -389,14 +390,15 @@ impl Callable {
389390
}
390391

391392
#[cfg(since_api = "4.3")]
392-
#[doc(alias = "get_argument_count")]
393-
pub fn arg_len(&self) -> usize {
393+
pub fn get_argument_count(&self) -> usize {
394394
self.as_inner().get_argument_count() as usize
395395
}
396396

397-
#[doc(alias = "get_bound_arguments_count")]
398-
pub fn bound_args_len(&self) -> i64 {
399-
self.as_inner().get_bound_arguments_count()
397+
pub fn get_bound_arguments_count(&self) -> usize {
398+
// To consistently return usize, we already fix the bug https://github.com/godotengine/godot/pull/98713 before Godot 4.4.
399+
let alleged_count = self.as_inner().get_bound_arguments_count();
400+
401+
alleged_count.max(0) as usize
400402
}
401403

402404
#[doc(hidden)]

itest/rust/src/builtin_tests/containers/callable_test.rs

+15-22
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use godot::builtin::{
1010
array, varray, Array, Callable, GString, NodePath, StringName, Variant, VariantArray,
1111
};
1212
use godot::classes::{Node2D, Object, RefCounted};
13-
use godot::init::GdextBuild;
1413
use godot::meta::ToGodot;
1514
use godot::obj::{Gd, NewAlloc, NewGd};
1615
use godot::register::{godot_api, GodotClass};
@@ -117,7 +116,7 @@ fn callable_static() {
117116
assert_eq!(result, "12345".to_variant());
118117

119118
#[cfg(since_api = "4.3")]
120-
assert_eq!(callable.arg_len(), 0); // Consistently doesn't work :)
119+
assert_eq!(callable.get_argument_count(), 0); // Consistently doesn't work :)
121120
}
122121

123122
#[itest]
@@ -247,37 +246,31 @@ fn callable_unbind() {
247246
fn callable_arg_len() {
248247
let obj = CallableTestObj::new_gd();
249248

250-
assert_eq!(obj.callable("foo").arg_len(), 1);
251-
assert_eq!(obj.callable("bar").arg_len(), 1);
252-
assert_eq!(obj.callable("baz").arg_len(), 4);
253-
assert_eq!(obj.callable("foo").unbind(10).arg_len(), 11);
249+
assert_eq!(obj.callable("foo").get_argument_count(), 1);
250+
assert_eq!(obj.callable("bar").get_argument_count(), 1);
251+
assert_eq!(obj.callable("baz").get_argument_count(), 4);
252+
assert_eq!(obj.callable("foo").unbind(10).get_argument_count(), 11);
254253
assert_eq!(
255254
obj.callable("baz")
256255
.bind(&[10.to_variant(), "hello".to_variant()])
257-
.arg_len(),
256+
.get_argument_count(),
258257
2
259258
);
260259
}
261260

262261
#[itest]
263262
fn callable_bound_args_len() {
263+
// Note: bug regarding get_bound_arguments_count() returning negative numbers has been fixed in godot-rust also for older versions.
264+
264265
let obj = CallableTestObj::new_gd();
266+
let original = obj.callable("foo");
265267

266-
assert_eq!(obj.callable("foo").bound_args_len(), 0);
267-
assert_eq!(obj.callable("foo").bindv(&varray![10]).bound_args_len(), 1);
268-
#[cfg(since_api = "4.3")]
269-
assert_eq!(
270-
obj.callable("foo").unbind(28).bound_args_len(),
271-
if GdextBuild::since_api("4.4") { 0 } else { -28 }
272-
);
273-
#[cfg(since_api = "4.3")]
274-
assert_eq!(
275-
obj.callable("foo")
276-
.bindv(&varray![10])
277-
.unbind(5)
278-
.bound_args_len(),
279-
if GdextBuild::since_api("4.4") { 1 } else { -4 }
280-
);
268+
assert_eq!(original.get_bound_arguments_count(), 0);
269+
assert_eq!(original.unbind(28).get_bound_arguments_count(), 0);
270+
271+
let with_1_arg = original.bindv(&varray![10]);
272+
assert_eq!(with_1_arg.get_bound_arguments_count(), 1);
273+
assert_eq!(with_1_arg.unbind(5).get_bound_arguments_count(), 1);
281274
}
282275

283276
#[itest]

0 commit comments

Comments
 (0)