-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
C#: Get singleton instances using the Core name #74280
C#: Get singleton instances using the Core name #74280
Conversation
RedworkDE
commented
Mar 3, 2023
- Followup to C#: Check if a class is a singleton using the Core name #73882
- Fixes Using ResourceUid in C# gives error #74270
<< itype.proxy_name | ||
<< ").Name);\n" INDENT3 "return singleton;\n" INDENT2 "}\n" INDENT1 "}\n"; | ||
<< INDENT4 "singleton = " C_METHOD_ENGINE_GET_SINGLETON "(\"" | ||
<< itype.cname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be itype.name
like we use in the static NativeName
field?
<< itype.cname | |
<< itype.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually not sure whats the difference between those two, beyond that one is a String
and the other a StringName
I picked cname
because you used type_cname
in your PR and that was the closest thing available here and it gave the correct result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell they come from https://github.com/godotengine/godot/blob/6ce1d89842ad400a640bedc692ec07bfb59bca6b/modules/mono/editor/bindings_generator.h#L543-L550 and I coudn't find any instance where they are set to different values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they are the same, probably to avoid converting between String
and StringName
multiple times.
In my PR, the Engine::has_singleton
method takes a StringName
so I used cname
. In this case, since the <<
operator takes a String
it may be better to use name
and avoid the conversion.
Actually, wait, they may not always be the same.
and I coudn't find any instance where they are set to different values.
🤔 I think I've seen some cases where they aren't. Maybe for the generated classes they happen to coincidentally always be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I tried both and they generate the exact same code, so I switched to avoid the unnecessary conversion and keep it in sync with the NativeName
.
6ce1d89
to
16a2a16
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but @neikeq may want to chime in about the difference between itype.name
and itype.cname
because I'm also a bit confused by it. We should probably add comments documenting them.
Now that this is using the native name, it would be more appropriate to use the
|
Thanks! |
Cherry-picked for 4.0.1. |