diff options
author | Danil Alexeev <danil@alexeev.xyz> | 2023-10-04 07:54:03 +0300 |
---|---|---|
committer | Danil Alexeev <danil@alexeev.xyz> | 2023-10-04 19:44:32 +0300 |
commit | ed0b3c08e15ee6345ece4b135a5e99870a8fc79f (patch) | |
tree | ac8fe0ff0c7dcb8d10e660c631946c8a3f58a6ee /core | |
parent | bfd78bb917887cfc1fd842ba23570394cad8bedb (diff) | |
download | redot-engine-ed0b3c08e15ee6345ece4b135a5e99870a8fc79f.tar.gz |
Core: Fix `Object::has_method()` for script static methods
Diffstat (limited to 'core')
-rw-r--r-- | core/object/object.cpp | 10 | ||||
-rw-r--r-- | core/object/script_language.h | 3 | ||||
-rw-r--r-- | core/object/script_language_extension.cpp | 1 | ||||
-rw-r--r-- | core/object/script_language_extension.h | 1 |
4 files changed, 14 insertions, 1 deletions
diff --git a/core/object/object.cpp b/core/object/object.cpp index f62b93d0ff..eb645b3a92 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -666,8 +666,16 @@ bool Object::has_method(const StringName &p_method) const { } MethodBind *method = ClassDB::get_method(get_class_name(), p_method); + if (method != nullptr) { + return true; + } - return method != nullptr; + const Script *scr = Object::cast_to<Script>(this); + if (scr != nullptr) { + return scr->has_static_method(p_method); + } + + return false; } Variant Object::getvar(const Variant &p_key, bool *r_valid) const { diff --git a/core/object/script_language.h b/core/object/script_language.h index ca08e9837a..5ff7cd8582 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -145,7 +145,10 @@ public: virtual PropertyInfo get_class_category() const; #endif // TOOLS_ENABLED + // TODO: In the next compat breakage rename to `*_script_*` to disambiguate from `Object::has_method()`. virtual bool has_method(const StringName &p_method) const = 0; + virtual bool has_static_method(const StringName &p_method) const { return false; } + virtual MethodInfo get_method_info(const StringName &p_method) const = 0; virtual bool is_tool() const = 0; diff --git a/core/object/script_language_extension.cpp b/core/object/script_language_extension.cpp index ce1109781a..a07bf63a02 100644 --- a/core/object/script_language_extension.cpp +++ b/core/object/script_language_extension.cpp @@ -55,6 +55,7 @@ void ScriptExtension::_bind_methods() { GDVIRTUAL_BIND(_get_class_icon_path); GDVIRTUAL_BIND(_has_method, "method"); + GDVIRTUAL_BIND(_has_static_method, "method"); GDVIRTUAL_BIND(_get_method_info, "method"); GDVIRTUAL_BIND(_is_tool); diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index beb8064a33..89bba80b90 100644 --- a/core/object/script_language_extension.h +++ b/core/object/script_language_extension.h @@ -99,6 +99,7 @@ public: #endif // TOOLS_ENABLED EXBIND1RC(bool, has_method, const StringName &) + EXBIND1RC(bool, has_static_method, const StringName &) GDVIRTUAL1RC(Dictionary, _get_method_info, const StringName &) virtual MethodInfo get_method_info(const StringName &p_method) const override { |