Skip to content

Commit d3ad99d

Browse files
committed
GDScriptNativeClass: Allow getting static function as callable
1 parent e4e024a commit d3ad99d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

modules/gdscript/gdscript.cpp

+9-2
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() {
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())
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)