Skip to content

Commit

Permalink
Add to ClassDB
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed Jan 28, 2024
1 parent 5b48574 commit 1fc6ac2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/core_bind.cpp
Expand Up @@ -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<Dictionary> ClassDB::class_get_method_list(const StringName &p_class, bool p_no_inheritance) const {
List<MethodInfo> methods;
::ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions core/core_bind.h
Expand Up @@ -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<Dictionary> 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;
Expand Down
19 changes: 19 additions & 0 deletions core/object/class_db.cpp
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions core/object/class_db.h
Expand Up @@ -404,6 +404,7 @@ class ClassDB {
static void get_method_list(const StringName &p_class, List<MethodInfo> *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<Pair<MethodInfo, uint32_t>> *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<uint32_t> get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
Expand Down
9 changes: 9 additions & 0 deletions doc/classes/ClassDB.xml
Expand Up @@ -65,6 +65,15 @@
Returns an array with the names all the integer constants of [param class] or its ancestry.
</description>
</method>
<method name="class_get_method_argument_count" qualifiers="const">
<return type="int" />
<param index="0" name="class" type="StringName" />
<param index="1" name="method" type="StringName" />
<param index="2" name="no_inheritance" type="bool" default="false" />
<description>
Returns the number of arguments of the method [param method] of [param class] or its ancestry if [param no_inheritance] is [code]false[/code].
</description>
</method>
<method name="class_get_method_list" qualifiers="const">
<return type="Dictionary[]" />
<param index="0" name="class" type="StringName" />
Expand Down

0 comments on commit 1fc6ac2

Please sign in to comment.