The Enum Keyword

Macaroni supports C++ enums using the same syntax as C++, with any discrepancies being inadvertent or accidental.

Here’s an example of an old style enum:

enum old_style
{
    A, B=3,
    C=4
};

And here’s an example of using the C++11 “class” enums:

enum class traffic_lights : char
{
    RED='r',
    GREEN='g',
    BLUE='b'
};

By default, a new unit is created for each enum, but only the header file contains anything with the cpp file being empty.

Note

Note that the order enumerations are declared in Macaroni is not the same as how they are generated. If order is important, use a ~block or do not rely on auto-incrementing default values.

Lua Scripts

The enum values are accessible from Lua using the GetValues command, like so:

print("Here's how you print out the enum values:")
local table = context.Root:Find("traffic_lights").Member:GetValues();
for k, v in pairs(table) do
    print(tostring(k) .. "=" .. tostring(v));
end

The above script produces the following output:

Here's how you print out the enum values:
BLUE='b'
GREEN='g'
RED='r'