FFI types
This section summarises the types that can be used in definitions for function signatures and field types. The types are split into multiple categories:
In each category, the table shows the following information:
- Description — What the type represents.
- Ammer type — How to write the type in definitions.
- Haxe call type — What the type will look like from a Haxe client of the
ammer
library.
- Haxe shortcut — Convenience alias for the type using an existing Haxe type, if any.
- C type — What the type maps to in a native library/in C language.
With a small number of exceptions, the ammer.ffi.*
types exist solely for defining the types of a native library's functions or fields. When an ammer
library is used from regular Haxe code, these types turn into a standard Haxe type, the conversion happens automatically. The exceptions are:
ammer.ffi.Array
ammer.ffi.Box
ammer.ffi.Bytes
ammer.ffi.Haxe
Primitive types
Description |
Ammer type |
Haxe call type |
Haxe shortcut |
C type |
Void |
ammer.ffi.Void |
Void |
Void |
void |
Boolean |
ammer.ffi.Bool |
Bool |
Bool |
bool |
Unsigned 8-bit integer |
ammer.ffi.UInt8 |
UInt |
- |
uint8_t |
Unsigned 16-bit integer |
ammer.ffi.UInt16 |
UInt |
- |
uint16_t |
Unsigned 32-bit integer |
ammer.ffi.UInt32 |
UInt |
UInt |
uint32_t |
Unsigned 64-bit integer |
ammer.ffi.UInt64 |
UInt |
- |
uint64_t |
Signed 8-bit integer |
ammer.ffi.Int8 |
Int |
- |
int8_t |
Signed 16-bit integer |
ammer.ffi.Int16 |
Int |
- |
int16_t |
Signed 32-bit integer |
ammer.ffi.Int32 |
Int |
Int |
int32_t |
Signed 64-bit integer |
ammer.ffi.Int64 |
Int |
haxe.Int64 |
int64_t |
Single-precision IEEE 754 number |
ammer.ffi.Float32 |
Single 1 |
Single 1 |
float |
Double-precision IEEE 754 number |
ammer.ffi.Float64 |
Float |
Float |
double |
String |
ammer.ffi.String |
String |
String |
const char* |
1: Single
Single
is only available on some Haxe targets. When a Float32
is used on a target that does not natively support single-precision floating-points, a lossy conversion is used from 64 bits.
Library datatypes
Description |
Ammer type |
Haxe shortcut |
C type |
Opaque pointer, struct pointer |
- |
T extends Struct ... |
(type)* |
Opaque data, struct |
ammer.ffi.Deref<T> |
T extends Struct ... |
(type) |
Opaque data, struct |
ammer.ffi.Alloc<T> |
T extends Struct ... |
(type) |
Haxe object |
ammer.ffi.Haxe<T> |
T |
void* |
Composed types
Description |
Ammer type |
Haxe shortcut |
C type |
A contiguous array |
ammer.ffi.Array<T> |
- |
(type)* |
Box |
ammer.ffi.Box<T> |
- |
(type)* |
Callback |
ammer.ffi.Callback<...> |
- |
- |
Special/marker types
Ammer type |
Meaning |
ammer.ffi.This |
Stands for the current struct instance, see instance methods |
ammer.ffi.Unsupported<...> |
An unsupported type: the type parameter (a string constant) will be passed to native calls. |
Standard library types
Description |
Ammer type |
C type |
File pointer |
ammer.ffi.FilePtr |
FILE* |