mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
Add methods to get argument count of methods
Added to: * `Callable`s * `Object`s * `ClassDB` * `Script(Instance)`s
This commit is contained in:
parent
0ace0a1292
commit
59bcc2888c
50 changed files with 821 additions and 3 deletions
|
@ -688,6 +688,59 @@ bool Object::has_method(const StringName &p_method) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
int Object::_get_method_argument_count_bind(const StringName &p_method) const {
|
||||
return get_method_argument_count(p_method);
|
||||
}
|
||||
|
||||
int Object::get_method_argument_count(const StringName &p_method, bool *r_is_valid) const {
|
||||
if (p_method == CoreStringNames::get_singleton()->_free) {
|
||||
if (r_is_valid) {
|
||||
*r_is_valid = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (script_instance) {
|
||||
bool valid = false;
|
||||
int ret = script_instance->get_method_argument_count(p_method, &valid);
|
||||
if (valid) {
|
||||
if (r_is_valid) {
|
||||
*r_is_valid = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
bool valid = false;
|
||||
int ret = ClassDB::get_method_argument_count(get_class_name(), p_method, &valid);
|
||||
if (valid) {
|
||||
if (r_is_valid) {
|
||||
*r_is_valid = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
const Script *scr = Object::cast_to<Script>(this);
|
||||
while (scr != nullptr) {
|
||||
bool valid = false;
|
||||
int ret = scr->get_script_method_argument_count(p_method, &valid);
|
||||
if (valid) {
|
||||
if (r_is_valid) {
|
||||
*r_is_valid = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
scr = scr->get_base_script().ptr();
|
||||
}
|
||||
|
||||
if (r_is_valid) {
|
||||
*r_is_valid = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Variant Object::getvar(const Variant &p_key, bool *r_valid) const {
|
||||
if (r_valid) {
|
||||
*r_valid = false;
|
||||
|
@ -1644,6 +1697,8 @@ void Object::_bind_methods() {
|
|||
|
||||
ClassDB::bind_method(D_METHOD("has_method", "method"), &Object::has_method);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_method_argument_count", "method"), &Object::_get_method_argument_count_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("has_signal", "signal"), &Object::has_signal);
|
||||
ClassDB::bind_method(D_METHOD("get_signal_list"), &Object::_get_signal_list);
|
||||
ClassDB::bind_method(D_METHOD("get_signal_connection_list", "signal"), &Object::_get_signal_connection_list);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue