Variables
Variables can be declared in library definitions using public static var
fields.
Example: variable in library definition
class Foobar extends ammer.def.Library<"foobar"> { public static var bar:Int; }
In this example, bar
is an integer variable in the Foobar
library.
As for function signatures, variable types are restricted to a subset of Haxe types. See FFI types.
Constants
If a value from a native library is available immediately, such as constants or macro definitions, it can be declared as a constant in the ammer
definition using a public static final
field.
Example: constant in library definition
class Foobar extends ammer.def.Library<"foobar"> { @:ammer.native("HELLO_WORLD") public static final helloWorld:String; }
In this example, helloWorld
is a string constant for the Foobar
ammer
library definition. The headers of the foobar
native library must ensure that HELLO_WORLD
is a valid C expression, for example with #define HELLO_WORLD "hello world"
.
@:ammer.native
can be used to specify the C expression which will be used to determine the value of a constant. There is no restriction to what the expression can be: it may be a literal, a constant, the result of a library call, and so forth. However, all constant values are initialised at the same time, typically before Haxe main
is reached, so the C expression should not be a mutable value, because it will not be updated.