12: Enums [✓] - royal-lang/rl GitHub Wiki
Enums are constants in Royal.
These are generally different constants than using var const which are variable constants which isn't always a compile-time constant.
Enums are always compile-time constants.
Enums can either contain multiple values or be a single value.
Enums do not have any address and the value is copied whenever used.
The default type of an enum is the type of the first member present if no type is given. If the enum is a single constant value then the type is that of the right-hand expression or value.
enum NAME = VALUE;
enum NAME
{
VALUE1;
VALUE2 = 2;
}
enum NAME : TYPE // TYPE specifies what type all values must be.
{
...
}
Example:
enum a = 100;
enum Color
{
red = 0;
green = 1;
blue = 2;
}
enum Message : string
{
success = "Success!";
error = "Error!";
}
var color = Color.green;
writeln(color);
writeln(color:int);
static foreach (c, colors)
{
pragma(msg, c);
}
var int colorInt = color;
var colorInt2 = color:int;