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

Expose Script.get_global_name() #7474

Closed
theraot opened this issue Aug 10, 2023 · 2 comments · Fixed by godotengine/godot#80487
Closed

Expose Script.get_global_name() #7474

theraot opened this issue Aug 10, 2023 · 2 comments · Fixed by godotengine/godot#80487
Milestone

Comments

@theraot
Copy link

theraot commented Aug 10, 2023

Describe the project you are working on

This applies to a couple addons:

  • A custom binary serializer
  • A code generator

There are also some other places that would benefit from a "nameof" operator, but that is a different case.

Describe the problem or limitation you are having in your project

I need to find the name of an arbitrary class given a reference.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Apparently this already exists in get_global_name, but it is not exposed to scripting. Thus, expose it to scripting.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Expose get_global_name to scripting.

If this enhancement will not be used often, can it be worked around with a few lines of script?

We can work around it for GDScript like this:

	var result := ""
	for global_class in ProjectSettings.get_global_class_list():
		if str(global_class["path"]) == script.resource_path:
			result = str(global_class["class"])
			break

However, that is only for GDScript. The method get_global_name exists in Script, and so it would also work for CSharpScript and any other future - or third party - derived class.

Is there a reason why this should be core and not an add-on in the asset library?

The method get_global_name is in core.

@raulsntos
Copy link
Member

Tangentially related:

We can work around it for GDScript like this [...] However, that is only for GDScript. The method get_global_name exists in Script, and so it would also work for CSharpScript and any other future - or third party - derived class.

ProjectSettings.get_global_class_list() should retrieve all registered global classes regardless of its scripting language. So it should already be working with CSharpScript. Maybe I misunderstood what you meant.

@theraot
Copy link
Author

theraot commented Aug 11, 2023

@raulsntos In all honesty, I was convinced it didn't, but I didn't check before posting. Thank you.

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

Successfully merging a pull request may close this issue.

4 participants