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

[Feature] Add support for enums #49

Open
SirLynix opened this issue Nov 18, 2024 · 0 comments
Open

[Feature] Add support for enums #49

SirLynix opened this issue Nov 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@SirLynix
Copy link
Contributor

Enums are one of those basic features NZSL is still missing.

They would basically be an other name for an integer with typed values.

Simple enums would be used like this:

enum LightType
{
    Directional, // underlying value: 0
    PointLight,  // underlying value: 1
    SpotLight    // underlying value: 2
}

and then they would be used like this:

let lightType = LightType.Directional;
if (lightType != LightType.PointLight)
    // ...

casting from and to integer would be explicit:

let lightType = LightType(1); // LightType.PointLight
let lightTypeInt = i32(lightType); // 1

It would also be necessary to be able to specify their underlying type and some values explicitly:

enum LightType : u32 // otherwise default underlying type would be i32
{
    Directional,     // underlying value: 0u32
    PointLight = 10, // underlying value: 10u32
    SpotLight        // underlying value: 11u32
}

I'd also like to support flags enums:

[flags]
enum LightTypeMask // default underlying type: u32
{
    Directional, // implicit value: 1
    Point,       // implicit value: 2
    Spot,        // implicit value: 4
}

// LightTypeMask supports &, | and ~ operators
@SirLynix SirLynix added the enhancement New feature or request label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant