Add methods to get argument count of methods

Added to:
* `Callable`s
* `Object`s
* `ClassDB`
* `Script(Instance)`s
This commit is contained in:
A Thousand Ships 2024-01-28 15:16:09 +01:00
parent 0ace0a1292
commit 59bcc2888c
No known key found for this signature in database
GPG key ID: 2033189A662F8BD7
50 changed files with 821 additions and 3 deletions

View file

@ -1735,6 +1735,34 @@ bool CSharpInstance::has_method(const StringName &p_method) const {
gchandle.get_intptr(), &p_method);
}
int CSharpInstance::get_method_argument_count(const StringName &p_method, bool *r_is_valid) const {
if (!script->is_valid() || !script->valid) {
if (r_is_valid) {
*r_is_valid = false;
}
return 0;
}
const CSharpScript *top = script.ptr();
while (top != nullptr) {
for (const CSharpScript::CSharpMethodInfo &E : top->methods) {
if (E.name == p_method) {
if (r_is_valid) {
*r_is_valid = true;
}
return E.method_info.arguments.size();
}
}
top = top->base_script.ptr();
}
if (r_is_valid) {
*r_is_valid = false;
}
return 0;
}
Variant CSharpInstance::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
ERR_FAIL_COND_V(!script.is_valid(), Variant());
@ -2579,6 +2607,29 @@ bool CSharpScript::has_method(const StringName &p_method) const {
return false;
}
int CSharpScript::get_script_method_argument_count(const StringName &p_method, bool *r_is_valid) const {
if (!valid) {
if (r_is_valid) {
*r_is_valid = false;
}
return 0;
}
for (const CSharpMethodInfo &E : methods) {
if (E.name == p_method) {
if (r_is_valid) {
*r_is_valid = true;
}
return E.method_info.arguments.size();
}
}
if (r_is_valid) {
*r_is_valid = false;
}
return 0;
}
MethodInfo CSharpScript::get_method_info(const StringName &p_method) const {
if (!valid) {
return MethodInfo();