Enums
Enums are sets of distinct, named values of the same type. In C, this may be an actual enum
declaration, or even a set of defines. Importantly, the values of an enum should be known at compile time.
To define an enum type, add @:build(ammer.def.Enum.build(..., ..., ...))
to a Haxe enum abstract
. The first argument parameter for ammer.def.Enum.build
should be a string identifying the native C type name. The second argument should be an FFI type. The third argument should be the ammer
library this type belongs to.
Enums should only contain variable declarations, one for each enum variant.
Example: enum definition
@:build(ammer.def.Enum.build("int", Int32, Foobar)) enum abstract FoobarEnum(Int) from Int to Int { @:ammer.native("FOOBAR_VAL1") var Val1; @:ammer.native("FOOBAR_VAL2") var Val2; // ... }
In this example, FoobarEnum
is an enum in the Foobar
library. The C type underlying this enum is a regular int
. There are two variants: Val1
and Val2
, which have the integer values available in the constants FOOBAR_VAL1
and FOOBAR_VAL2
at compile time.
Compilation
In order for Haxe to be able to use ammer
enums like regular enum abstract
s, the value of each variant must be known at compile time. ammer
will automatically extract the appropriate values by invoking the C compiler.
Linking
Enums should be linked with the parent library using the @:ammer.sub(...)
metadata to avoid compilation errors. See linking subdefinitions.