diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-03-13 22:16:43 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-03-13 22:16:43 +0100 |
commit | a1c476f9d754e9c3420eb092b236325029151c0b (patch) | |
tree | ffa5bd5899adf40ed1c9a67a8425e4c777aeddcc /modules/gdscript/gdscript.cpp | |
parent | 89ba6178248569813cbd8cc44e402b411b88ac36 (diff) | |
parent | 59bcc2888c0c6002428ed1040ef6b36957a80e98 (diff) | |
download | redot-engine-a1c476f9d754e9c3420eb092b236325029151c0b.tar.gz |
Merge pull request #87680 from AThousandShips/the_angry_count
Add methods to get argument count of methods
Diffstat (limited to 'modules/gdscript/gdscript.cpp')
-rw-r--r-- | modules/gdscript/gdscript.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 94aa077014..8e74de4242 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -354,6 +354,21 @@ bool GDScript::has_static_method(const StringName &p_method) const { return member_functions.has(p_method) && member_functions[p_method]->is_static(); } +int GDScript::get_script_method_argument_count(const StringName &p_method, bool *r_is_valid) const { + HashMap<StringName, GDScriptFunction *>::ConstIterator E = member_functions.find(p_method); + if (!E) { + if (r_is_valid) { + *r_is_valid = false; + } + return 0; + } + + if (r_is_valid) { + *r_is_valid = true; + } + return E->value->get_argument_count(); +} + MethodInfo GDScript::get_method_info(const StringName &p_method) const { HashMap<StringName, GDScriptFunction *>::ConstIterator E = member_functions.find(p_method); if (!E) { @@ -1916,6 +1931,25 @@ bool GDScriptInstance::has_method(const StringName &p_method) const { return false; } +int GDScriptInstance::get_method_argument_count(const StringName &p_method, bool *r_is_valid) const { + const GDScript *sptr = script.ptr(); + while (sptr) { + HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(p_method); + if (E) { + if (r_is_valid) { + *r_is_valid = true; + } + return E->value->get_argument_count(); + } + sptr = sptr->_base; + } + + if (r_is_valid) { + *r_is_valid = false; + } + return 0; +} + Variant GDScriptInstance::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { GDScript *sptr = script.ptr(); if (unlikely(p_method == SNAME("_ready"))) { |