Skip to content

Enum Code Features

One enum definition, one set of capabilities — Archmage carries them into every supported language, each rendered in that language’s own idioms and type system.

Each enum type becomes a distinct named type backed by an integer. Items are defined as typed constants. Where necessary, item names are prefixed with the type name to prevent naming conflicts. An optional prefix option in the type definition overrides the default prefix, if any.

Each enum type can specify its underlying integer type — int, int8, int16, int32, int64, uint, uint8, uint16, uint32, or uint64. The generated code enforces range bounds in the Parse function.

Every enum value has a canonical string representation — by default the item name, overridable via the string field in the definition. The generated code converts in both directions: enum to string and string to enum.

The generated Parse function (or equivalent) accepts multiple input formats:

  • Item name, or its string override if defined — case-insensitive
  • TypeName(n) — a fallback numeric format, e.g., "Armor(99)"
  • Decimal and hexadecimal integers (e.g., "1", "0x1F")

When parsing fails, the function returns an error (or throws an exception, depending on the language) rather than silently returning a zero value.

The generated IsValid function checks if a given value corresponds to a defined enum item. For bitflag enums, it decomposes the value and validates each constituent flag individually.

Enum values serialize as integers in JSON. The string representation exists for runtime use only.

The generated code exposes the full set of valid enum values as an ordered list. Sentinel items are excluded. For duplicate values, only the first-defined item is included.

Items marked with sentinel: true serve as boundary markers (e.g., Count). They are excluded from the valid-value set, the AllValues list, and the name map. They appear only as constants in the generated code.

Multiple items can share the same integer value. Each has its own constant. For string conversion, the first-defined item’s name is used for that value; all names remain valid for parsing.

Enum types marked with bitflags: true gain additional capabilities:

  • Parsing supports comma-separated flag combinations — e.g., "frost, fire" yields the bitwise OR: Frost | Fire
  • String conversion mirrors the above behavior, formatting composite values as comma-separated strings — e.g., Frost | Fire yields "frost, fire"
  • IsValid verifies that a value can be fully decomposed into recognized flags