HxFFI is a Haxe library that allows you to quickly use native libraries quickly without any wrappers! It does this using LibFFI and uses a similar method to JNA.
C Type | EasyLibrary Type | Haxe Type | FFI Type |
---|---|---|---|
void | Void | Void | ffi.Type.VOID |
char* | String | String | ffi.Type.POINTER |
void* | Pointer | ffi.Pointer | ffi.Type.POINTER |
float | Single | Float | ffi.Type.FLOAT |
double | Float | Float | ffi.Type.DOUBLE |
int | Int / SInt | Int | ffi.Type.INT |
uint | UInt | Int | ffi.Type.UINT |
long | Int64 / SInt64 | haxe.Int64 | ffi.Type.SINT64 |
ulong | UInt64 | haxe.Int64 | ffi.Type.UINT64 |
__int32_t__ | Int32 / SInt32 | Int | ffi.Type.SINT32 |
__uint32_t__ | UInt32 | Int | ffi.Type.UINT32 |
__int16_t / short__ | Int16 / SInt16 | Int | ffi.Type.SINT16 |
__uint16_t / ushort__ | UInt16 | Int | ffi.Type.UINT16 |
__int8_t / char__ | Int8 / SInt8 | Int | ffi.Type.SINT8 |
__uint8_t / uchar__ | UInt8 | Int | ffi.Type.UINT8 |
struct | Struct<ordered types...> | Array<Dynamic> | ffi.Type.createStruct(...) |
You can use FFI easily and transparently by extending ffi.lib.EasyLibrary
as seen in the samples.
Structs can be declared like this:
@:struct(SDLRect => {
var x:SInt16;
var y:SInt16;
var w:UInt16;
var h:UInt16;
})
@:lib("...")
class SDL {
...
public function SDL_BlitSurface(...,dest: SDLRect...):Int;
}