Skip to content

[Feature] Add support for enums #49

@SirLynix

Description

@SirLynix

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions