Closed dugramen closed 8 months ago
Commenting to boost this, I need to be able to get this data and more about arbitrary callable's signatures.
@IntangibleMatter Please don't bump issues without contributing significant new information. Use the :+1: reaction button on the first post instead.
Will take a look at possibly implementing this, will see how it goes
Made quite a bit of progress, will probably open a PR soon
This is already possible with the following code:
func GetMethodArgCount(m: Callable):
for f in get_method_list():
var fn = get(f.name)
if m.get_method() == f.name:
return f.args.size()
return 0
That doesn't cover everything, you can't use it for lambdas or for example, also it doesn't matter now since this has been added as a feature so you can just use the method
Describe the project you are working on
Editor plugins
Describe the problem or limitation you are having in your project
Callable.unbind() allows unbinding a number of arguments, but there is no way to dynamically know how many arguments are allowed/should be unbound
Describe the feature / enhancement and how it helps to overcome the problem or limitation
A new method on Callable, called get_argument_count() or get_allowed_arguments_count() that returns the number of arguments allowed by the callable
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Here are 2 example usages:
To unbind some unknown Callable for a signal:
Example of a reusable, JavaScript style, array mapper. Only possible if this is implemented (optional index and array)
Which could be used like so:
If this enhancement will not be used often, can it be worked around with a few lines of script?
It's only possible with known Callables, but it's not currently possible to implement something like the above utility function
Is there a reason why this should be core and not an add-on in the asset library?
I don't think an add-on can do this