Skip to content

Commit 7444da7

Browse files
committed
Merge pull request godotengine#97374 from rune-scape/get-native-static-callable
GDScriptNativeClass: Allow getting static function as callable
2 parents cfc05c5 + d3ad99d commit 7444da7

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

modules/gdscript/gdscript.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,16 @@ bool GDScriptNativeClass::_get(const StringName &p_name, Variant &r_ret) const {
7676
if (ok) {
7777
r_ret = v;
7878
return true;
79-
} else {
80-
return false;
8179
}
80+
81+
MethodBind *method = ClassDB::get_method(name, p_name);
82+
if (method && method->is_static()) {
83+
// Native static method.
84+
r_ret = Callable(this, p_name);
85+
return true;
86+
}
87+
88+
return false;
8289
}
8390

8491
void GDScriptNativeClass::_bind_methods() {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
func get_parse_string(t: Variant):
2+
return t.parse_string
3+
4+
func test():
5+
var a: Callable = JSON.parse_string
6+
var b: Callable = get_parse_string(JSON)
7+
prints(a.call("{\"test\": \"a\"}"), a.is_valid())
8+
prints(b.call("{\"test\": \"b\"}"), b.is_valid())
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GDTEST_OK
2+
{ "test": "a" } false
3+
{ "test": "b" } false

0 commit comments

Comments
 (0)