diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-01-28 15:16:09 +0100 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-03-10 11:02:43 +0100 |
commit | 59bcc2888c0c6002428ed1040ef6b36957a80e98 (patch) | |
tree | e78cf547c47bb31e35827eff93f6e7c492399605 /modules/mono/csharp_script.cpp | |
parent | 0ace0a129284ffc6646b199699c1607a316fcec0 (diff) | |
download | redot-engine-59bcc2888c0c6002428ed1040ef6b36957a80e98.tar.gz |
Add methods to get argument count of methods
Added to:
* `Callable`s
* `Object`s
* `ClassDB`
* `Script(Instance)`s
Diffstat (limited to 'modules/mono/csharp_script.cpp')
-rw-r--r-- | modules/mono/csharp_script.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 93fb5f1dc6..858d1d3e4e 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -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(); |