-
Notifications
You must be signed in to change notification settings - Fork 2
Description
enum
enum would help with speed at runtime when checking between multiple values:
enum ConnectionType {
INET;
INET6;
UNIX;
};
print(INET == ConnectionType.INET);
INET and ConnectionType.INET both compile to 1, so the resulting code would be similar to:
print(1 == 1)enum values may be assigned with an "initial" value; values assigned afterwards take the value of the former, adding one:
enum Numbers {
ZERO = 48;
ONE;
TWO;
THREE;
FOUR;
FIVE;
SIX;
SEVEN;
EIGHT;
NINE;
TEN;
};
Enumeration values could also be assigned after an initial
assignment, and to any integer, negative or positive:
enum Numbers {
NFIVE = -5;
NFOUR;
NTHREE;
ZERO = 0;
ONE;
TWO;
TEN = 10;
};
Enumeration values can't go backwards:
enum BadEnum {
ONE;
ZERO = 0; -- errors during compilation
};
const
const values are like enumerations, but only one value is assigned per statement:
--- FusionScript
const max_char = 255;
print(string.char(max_char));
--- Lua
print(255);Unlike enumerations, const values can also be true, false, nil, or a string:
--- FusionScript
const format_pattern = "%s: %s";
print(format_pattern:format(name, message));
--- Lua
print(("%s: %s"):format(name, message))CONSIDERATION: "%s: %s":format() is not valid Lua. Instead, the
value - if not used only as a value, for instance, as a callable or indexable
object - should be wrapped in parenthesis first.