Skip to content

Commit

Permalink
GDScriptNativeClass: Allow getting static function as callable
Browse files Browse the repository at this point in the history
  • Loading branch information
rune-scape committed Sep 23, 2024
1 parent e4e024a commit d3ad99d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ bool GDScriptNativeClass::_get(const StringName &p_name, Variant &r_ret) const {
if (ok) {
r_ret = v;
return true;
} else {
return false;
}

MethodBind *method = ClassDB::get_method(name, p_name);
if (method && method->is_static()) {
// Native static method.
r_ret = Callable(this, p_name);
return true;
}

return false;
}

void GDScriptNativeClass::_bind_methods() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
func get_parse_string(t: Variant):
return t.parse_string

func test():
var a: Callable = JSON.parse_string
var b: Callable = get_parse_string(JSON)
prints(a.call("{\"test\": \"a\"}"), a.is_valid())
prints(b.call("{\"test\": \"b\"}"), b.is_valid())
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GDTEST_OK
{ "test": "a" } false
{ "test": "b" } false

0 comments on commit d3ad99d

Please sign in to comment.