Skip to content
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

Merged

Conversation

RedworkDE
Copy link
Member

@RedworkDE RedworkDE requested a review from a team as a code owner March 3, 2023 09:08
@akien-mga akien-mga added this to the 4.1 milestone Mar 3, 2023
@neikeq neikeq self-requested a review March 3, 2023 12:24
<< itype.proxy_name
<< ").Name);\n" INDENT3 "return singleton;\n" INDENT2 "}\n" INDENT1 "}\n";
<< INDENT4 "singleton = " C_METHOD_ENGINE_GET_SINGLETON "(\""
<< itype.cname
Copy link
Member

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?

Suggested change
<< itype.cname
<< itype.name

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

@raulsntos raulsntos Mar 3, 2023

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.

Copy link
Member Author

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.

@RedworkDE RedworkDE force-pushed the net-get-singleton-core-name branch from 6ce1d89 to 16a2a16 Compare March 3, 2023 15:30
Copy link
Member

@raulsntos raulsntos left a 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.

@neikeq
Copy link
Contributor

neikeq commented Mar 4, 2023

Now that this is using the native name, it would be more appropriate to use the NativeName field and update godotsharp_engine_get_singleton to use StringName. But we can't do the latter without breaking compat (we could add a new native call, but it's not worth for this), so it will have to be in Godot 5.

itype.name and itype.cname are the same, but the former is a String and the latter StringName.

@akien-mga akien-mga merged commit dd1b158 into godotengine:master Mar 5, 2023
@akien-mga
Copy link
Member

Thanks!

@RedworkDE RedworkDE deleted the net-get-singleton-core-name branch March 5, 2023 12:52
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using ResourceUid in C# gives error
5 participants