Skip to content

Commit f25b07b

Browse files
committed
Callable: rename from_local_static -> from_class_static, allow multithreading
1 parent 56f369f commit f25b07b

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

godot-core/src/builtin/callable.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Callable {
7272
/// If the builtin type does not have the method, the returned callable will be invalid.
7373
///
7474
/// Static builtin methods (e.g. `String.humanize_size`) are not supported in reflection as of Godot 4.4. For static _class_ functions,
75-
/// use [`from_local_static()`][Self::from_local_static] instead.
75+
/// use [`from_class_static()`][Self::from_class_static] instead.
7676
///
7777
/// _Godot equivalent: `Callable.create(Variant variant, StringName method)`_
7878
#[cfg(since_api = "4.3")]
@@ -84,17 +84,15 @@ impl Callable {
8484
inner::InnerCallable::create(variant, method_name)
8585
}
8686

87-
/// Create a callable for the static method `class_name::function` (single-threaded).
87+
/// Create a callable for the static method `class_name::function`
8888
///
89-
/// Allows you to call static functions through `Callable`.
89+
/// Allows you to call static functions through `Callable`. Allows both single- and multi-threaded calls; what happens on Godot side
90+
/// is your responsibility.
9091
///
91-
/// Does not support built-in types (such as `String`), only classes.
92-
///
93-
/// # Compatibility
94-
/// Not available before Godot 4.4. Library versions <0.3 used to provide this, however the polyfill used to emulate it was half-broken
95-
/// (not supporting signals, bind(), method_name(), is_valid(), etc).
92+
/// Does not support built-in types (such as `String`), only classes. Static functions on built-in types are not supported in Godot's
93+
/// reflection APIs at the moment.
9694
#[cfg(since_api = "4.4")]
97-
pub fn from_local_static(
95+
pub fn from_class_static(
9896
class_name: impl meta::AsArg<StringName>,
9997
function_name: impl meta::AsArg<StringName>,
10098
) -> Self {
@@ -103,7 +101,7 @@ impl Callable {
103101

104102
let callable_name = format!("{class_name}.{function_name}");
105103

106-
Self::from_local_fn(&callable_name, move |args| {
104+
let function = move |args: &[&Variant]| {
107105
let args = args.iter().cloned().cloned().collect::<Vec<_>>();
108106

109107
let result: Variant = classes::ClassDb::singleton().class_call_static(
@@ -112,7 +110,24 @@ impl Callable {
112110
args.as_slice(),
113111
);
114112
result
115-
})
113+
};
114+
115+
#[cfg(feature = "experimental-threads")]
116+
let callable = Self::from_sync_fn(&callable_name, function);
117+
118+
#[cfg(not(feature = "experimental-threads"))]
119+
let callable = Self::from_local_fn(&callable_name, function);
120+
121+
callable
122+
}
123+
124+
#[deprecated = "Renamed to `from_class_static`."]
125+
#[cfg(since_api = "4.4")]
126+
pub fn from_local_static(
127+
class_name: impl meta::AsArg<StringName>,
128+
function_name: impl meta::AsArg<StringName>,
129+
) -> Self {
130+
Self::from_class_static(class_name, function_name)
116131
}
117132

118133
fn default_callable_custom_info() -> CallableCustomInfo {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn callable_variant_method() {
140140
#[itest]
141141
#[cfg(since_api = "4.4")]
142142
fn callable_static() {
143-
let callable = Callable::from_local_static("CallableTestObj", "concat_array");
143+
let callable = Callable::from_class_static("CallableTestObj", "concat_array");
144144

145145
assert_eq!(callable.object(), None);
146146
assert_eq!(callable.object_id(), None);
@@ -170,7 +170,7 @@ fn callable_static() {
170170
#[itest]
171171
#[cfg(since_api = "4.4")]
172172
fn callable_static_bind() {
173-
let callable = Callable::from_local_static("CallableTestObj", "concat_array");
173+
let callable = Callable::from_class_static("CallableTestObj", "concat_array");
174174
assert!(callable.is_valid());
175175

176176
// Test varying binds to static callables.

0 commit comments

Comments
 (0)