diff --git a/core/core_bind.cpp b/core/core_bind.cpp index e5363f9acc8d6a..25ff12c6b5a54b 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -1432,6 +1432,10 @@ bool ClassDB::class_has_method(const StringName &p_class, const StringName &p_me return ::ClassDB::has_method(p_class, p_method, p_no_inheritance); } +int ClassDB::class_get_method_argument_count(const StringName &p_class, const StringName &p_method, bool p_no_inheritance) const { + return ::ClassDB::get_method_argument_count(p_class, p_method, p_no_inheritance); +} + TypedArray ClassDB::class_get_method_list(const StringName &p_class, bool p_no_inheritance) const { List methods; ::ClassDB::get_method_list(p_class, &methods, p_no_inheritance); @@ -1536,6 +1540,8 @@ void ClassDB::_bind_methods() { ::ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &ClassDB::class_has_method, DEFVAL(false)); + ::ClassDB::bind_method(D_METHOD("class_get_method_argument_count", "class", "method", "no_inheritance"), &ClassDB::class_get_method_argument_count, DEFVAL(false)); + ::ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &ClassDB::class_get_method_list, DEFVAL(false)); ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &ClassDB::class_get_integer_constant_list, DEFVAL(false)); diff --git a/core/core_bind.h b/core/core_bind.h index 94d95f2ce987c0..07e7bc8af3117d 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -445,6 +445,8 @@ class ClassDB : public Object { bool class_has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false) const; + int class_get_method_argument_count(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false) const; + TypedArray class_get_method_list(const StringName &p_class, bool p_no_inheritance = false) const; PackedStringArray class_get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const; diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 45fbb19f88b665..ebb939266a6367 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -1425,6 +1425,25 @@ bool ClassDB::has_method(const StringName &p_class, const StringName &p_method, return false; } +int ClassDB::get_method_argument_count(const StringName &p_class, const StringName &p_method, bool p_no_inheritance) { + OBJTYPE_RLOCK; + + ClassInfo *type = classes.getptr(p_class); + + while (type) { + MethodBind **method = type->method_map.getptr(p_method); + if (method && *method) { + return (*method)->get_argument_count(); + } + if (p_no_inheritance) { + return 0; + } + type = type->inherits_ptr; + } + + return 0; +} + void ClassDB::bind_method_custom(const StringName &p_class, MethodBind *p_method) { _bind_method_custom(p_class, p_method, false); } diff --git a/core/object/class_db.h b/core/object/class_db.h index 7a4ee1afa4518a..6f29aec31439a4 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -404,6 +404,7 @@ class ClassDB { static void get_method_list(const StringName &p_class, List *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false); static void get_method_list_with_compatibility(const StringName &p_class, List> *p_methods_with_hash, bool p_no_inheritance = false, bool p_exclude_from_properties = false); static bool get_method_info(const StringName &p_class, const StringName &p_method, MethodInfo *r_info, bool p_no_inheritance = false, bool p_exclude_from_properties = false); + static int get_method_argument_count(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false); static MethodBind *get_method(const StringName &p_class, const StringName &p_name); static MethodBind *get_method_with_compatibility(const StringName &p_class, const StringName &p_name, uint64_t p_hash, bool *r_method_exists = nullptr, bool *r_is_deprecated = nullptr); static Vector get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name); diff --git a/doc/classes/ClassDB.xml b/doc/classes/ClassDB.xml index d24181c3d31fc3..3f714060919339 100644 --- a/doc/classes/ClassDB.xml +++ b/doc/classes/ClassDB.xml @@ -65,6 +65,15 @@ Returns an array with the names all the integer constants of [param class] or its ancestry. + + + + + + + Returns the number of arguments of the method [param method] of [param class] or its ancestry if [param no_inheritance] is [code]false[/code]. + +