You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the problem or limitation you are having in your project
The Godot engine does not have a type-safe way to represent a value that could be one of several specified types. For example, there is no way to declare that a return value will be a meaningful answer OR an error code. Instead, you must return the value AND an error code, which makes for both less efficient and less readable code. Another example: there is no way to declare that a value will represent a type by being either a Variant::Type, a class name StringName, OR a script Ref<Script>. These limitations affect both core development and user scripting.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
A tagged-union is a way to represent values which may be one of several types. Introducing tagged unions to GDScript already has a ton of support (see #737). Having tagged unions in core would not only be a first step towards making that a reality, it would also improve the core development experience.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
One tricky aspect is figuring out how this implementation of std::variant would integrate with Godot's existing Variant type. One route would be to reimplement Godot's Variant as a special case of the more general std::variant implementation, but this approach is probably way too much work. I'm open to ideas for this particular challenge.
If this enhancement will not be used often, can it be worked around with a few lines of script?
No.
Is there a reason why this should be core and not an add-on in the asset library?
N/A.
The text was updated successfully, but these errors were encountered:
Perhaps. And I'd be happy with that as well. Although I suspect that implementing general union type may not be much more work than implementing a dedicated Option/Result type. I'm happy to be proven wrong though.
Describe the project you are working on
Godot engine.
Describe the problem or limitation you are having in your project
The Godot engine does not have a type-safe way to represent a value that could be one of several specified types. For example, there is no way to declare that a return value will be a meaningful answer OR an error code. Instead, you must return the value AND an error code, which makes for both less efficient and less readable code. Another example: there is no way to declare that a value will represent a type by being either a Variant::Type, a class name
StringName
, OR a scriptRef<Script>
. These limitations affect both core development and user scripting.Describe the feature / enhancement and how it helps to overcome the problem or limitation
A tagged-union is a way to represent values which may be one of several types. Introducing tagged unions to GDScript already has a ton of support (see #737). Having tagged unions in core would not only be a first step towards making that a reality, it would also improve the core development experience.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I propose introducing a union type to core that functions in much the same way as C++17's
std::variant
. Ifstd::variant
cannot be used directly because of the drawbacks associated with using the standard library, I propose rolling our own based on the many open-source implementations ofstd::variant
(or perhaps boost's variant https://www.boost.org/doc/libs/1_83_0/doc/html/variant.html or variant2 https://www.boost.org/doc/libs/develop/libs/variant2/doc/html/variant2.html).One tricky aspect is figuring out how this implementation of
std::variant
would integrate with Godot's existingVariant
type. One route would be to reimplement Godot'sVariant
as a special case of the more generalstd::variant
implementation, but this approach is probably way too much work. I'm open to ideas for this particular challenge.If this enhancement will not be used often, can it be worked around with a few lines of script?
No.
Is there a reason why this should be core and not an add-on in the asset library?
N/A.
The text was updated successfully, but these errors were encountered: