New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
has_method does not work on class #22838
Comments
Changing this line in object.h Line 652 in b17e71b
and making this bool virtual seems to (partially) fix the issue. The Script class has its own has_method so it should work if correctly implemented.
As I didn't test it with VisualScript and C# I am not comfortable committing this change. |
The scripting API doesn't support static method. As such,
I don't understand how that would change anything. Could you give more details? |
In Objects there is this method defined: Line 652 in b17e71b
If I get it right this method checks if the method is either specified in an atached script or in the class. However there is also a Line 127 in b17e71b
This already caused duplicate issues: #10785 If I understand c++ correctly, correct my if I'm wrong, the following happens:
This makes it possible to check for static method in inner classes. The inner classes are of type GDScript and their Note that I only tested this with GDScript. I have not testet it in VisualScript and C# nor do I plan learning C# just for that. Also I don't know if this could potentialy create other issues with |
Ok, changing The biggest one is that just overriding will get rid of the functionality in object's implementation. With this "fix"
Furthermore static functions of parents can not be found, although they are callable. Advice would be appreciated. Or if someone wants to try it themself, go for it. |
If someone is interested: Here are the test cases I could think of:
|
First of all,
This can be fixed by calling the object's implementation if the method was not found.
This should be simple as well. Just calling This won't work in any other language (except VisualScript perhaps), unless they have a way to get the |
Thanks for the tip! I made the changes and it works fine. I have renamed |
This will be properly fixable when methods become actual members. @vnen is going to work on this for Godot 3.2, so kicking there. |
Will this be a part of 4.0 or was it just postponed to the latest available version? I guess it is related to the introduction of a |
Yes, I believe this is being postponed till 4.0 (or, if not then, 4.1) since reduz's "when methods become actual members" comment refers to the introduction of the I suspect the solution will just be changing the implementation of
My guess would be that it would be the same method for both, but it would just be updated so that instance and static methods work on ScriptInstances and static methods work on Scripts. |
Just FYI, this problem occurs too with regular classes, not just var klass = CanvasItem
# prints `false`
print(klass.has_method("hide")) Arguably here you could use |
Is this still reproducible in 4.0? (I believe so and it might be tracked in newer issues too, but I didn't check.) |
Godot version:
current master
OS/device including version:
Windows, don't think it matters
Issue description:
Investigating #22833 I found out that
has_method
does not work with classes.Consider the following script:
In #22833 this bug makes it impossible to use a static func of a class in array.sort_custom().
Steps to reproduce:
Call
has_method
on a class.Minimal reproduction project:
sfhm.zip
The text was updated successfully, but these errors were encountered: