Skip to content

enum_proposal

Matěj Štágl edited this page May 19, 2022 · 2 revisions

Enum proposal

Enum is a readonly specialisation of table with automatic incremental indexing of it's properties. Multiple keys can share the same value. An empty enum is declared as:

enum E {
 
}

To add pairs, assignment = syntax is used.

enum E {
 Red = 0,
 Green = 1,
 Yellow = 2
}
  • RHS of a pair can be ommited.
    • if it's a first pair, 0 is assigned implicitly
    • else value of a previous pair increased by one is assigned implicitly
enum E {
 Aqua, // implicit RHS "= 0"
 Red = 11,
 Yellow = 10,
 Blue, // implicit RHS "= 11"
 Orange // implicit RHS "= 12"
}

Annotations can be attached to enums.

@myAnnotation
enum E {

}

Enums are readonly. Attempting to write to an enum results in a runtime error:

enum Colors {
 Red
}

Colors.Red = 10 // throws: Cannot write to enum "Colors". Enums are readonly.
Clone this wiki locally