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

Class namespacing #8189

Closed
ghost opened this issue Oct 19, 2023 · 3 comments
Closed

Class namespacing #8189

ghost opened this issue Oct 19, 2023 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 19, 2023

Describe the project you are working on

I'm working on gdserialize, a schema-based serialization addon for Godot that works with JSON schema.

Describe the problem or limitation you are having in your project

As described in #8176, the naming of classes such as Serializer may lead to conflicts between addons. As the number of available assets for Godot increase with its popularity, a naming conflict is increasingly likely.

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

The GDScript language should receive the ability to namespace classes in order to avoid conflicts.

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

Namespace naming

Namespaces are named similar to class names. Namespaces may not have the same name as a class. Namespaces may have sub-namespaces separated with a dot (.), similar to class members or inline classes.

The namespace keyword

This keyword would prefix the class_name keyword to specify a namespace:

namespace GDSerialize
class_name Serializer
extends RefCounted

Namespaces may also be nested:

namespace GDSerialize.Serializers
class_name Serializer
extends RefCounted

Referencing classes

Classes can be referenced by their full name:

var foo = GDSerialize.Serializer.new()

Alternatively, a file-wide shorthand can be specified using the using keyword, which will attempt to resolve the specified class names in the global scope as well as in the specified namespaces. Multiple using keywords are allowed.

extends Node
using GDSerialize

var foo = Serializer.new()

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

Class names can be prefixed with the desired namespace name. This will make the code less readable.

class_name GDSerializeSerializer

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

It is not possible to implement this as an add-on.

@dalexeev
Copy link
Member

@ghost
Copy link
Author

ghost commented Oct 19, 2023

Wow, I didn't find this one, my search failed me. My bad.

@Calinou
Copy link
Member

Calinou commented Oct 19, 2023

Thanks for the proposal! Consolidating in #1566.

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

No branches or pull requests

3 participants