Foreign Function Interface
zune.ffi
A library to interact with foreign functions and libraries.
Properties
prefix
The recommended prefix for the library file.
Platforms:
- Windows: none
- Linux:
lib - macOS:
lib
prefix: stringsuffix
The recommended suffix for the library file.
Platforms:
- Windows:
dll - Linux:
so - macOS:
dylib
suffix: stringtypes
types: <<table> = {
void: FFIDataType,
i8: FFIDataType,
u8: FFIDataType,
i16: FFIDataType,
u16: FFIDataType,
i32: FFIDataType,
u32: FFIDataType,
i64: FFIDataType,
u64: FFIDataType,
float: FFIDataType,
double: FFIDataType,
pointer: FFIPointerType,
vector2_32: FFIVectorType,
vector3_32: FFIVectorType,
}table<table> = {
void: FFIDataType,
i8: FFIDataType,
u8: FFIDataType,
i16: FFIDataType,
u16: FFIDataType,
i32: FFIDataType,
u32: FFIDataType,
i64: FFIDataType,
u64: FFIDataType,
float: FFIDataType,
double: FFIDataType,
pointer: FFIPointerType,
vector2_32: FFIVectorType,
vector3_32: FFIVectorType,
}>null
null: FFIPointerFunctions
ptr
ptr(src: FFIPointer): FFIPointerParameters
src: FFIPointer- The pointer to reference.
Throws
- Memory Error
ptrFromAddress
ptrFromAddress(src: buffer): FFIPointerParameters
src: buffer- The address of the pointer.
Throws
- Memory Error
getLuaState
Returns the lua state.
getLuaState(mainthread: boolean?): FFIPointerParameters
mainthread: boolean?- Whether to get the main thread or the current thread.- default:
false
- default:
Throws
- Memory Error
alloc
alloc(size: number, alignment: number?): FFIPointerParameters
size: number- The size to allocate.alignment: number?- The alignment to allocate.- default:
1
- default:
Throws
- FFI Error
- Memory Error
create
create(type: -- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerTypeFFIAnyDataType-- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerType): FFIPointerParameters
type: FFIAnyDataType- The data type to allocate.
Throws
- FFI Error
- Memory Error
free
free(src: FFIPointer): ()Parameters
src: FFIPointer- The pointer to free. If the pointer is static, it must have a known size.
Throws
- FFI Error
- Memory Error
dupe
dupe(src: buffer | FFIPointer | vector): FFIPointerParameters
src: buffer | FFIPointer | vector- The pointer to duplicate. If the source is a static pointer, it must have a known size.
Throws
- Memory Error
tagName
tagName(tag: number): string?Parameters
tag: number- The tag id to get the name of.
struct
Creates a structure data type.
- The order of the fields is the number index of the field table.
- There cannot be multiple fields in the same field table.
- Multiple fields with the same field name is not allowed.
struct(fields: {{[string]: -- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerTypeFFIAnyDataType-- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerType}}): FFIStructureTypeParameters
fields: {{ [string]: FFIAnyDataType }}- The fields of the structure.
Throws
- FFI Error
- Memory Error
fn
fn(definition: -- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerType
export type FFIFunctionDefintion = {
returns: FFIAnyDataType,
args: {FFIAnyDataType}
}FFIFunctionDefintion-- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerType
export type FFIFunctionDefintion = {
returns: FFIAnyDataType,
args: {FFIAnyDataType}
}, srcPtr: FFIPointer): ((...any) -> any)Parameters
definition: FFIFunctionDefintion- The function definition.returns: FFIAnyDataType- The return type of the function.args: {FFIAnyDataType}- The argument types of the function.
srcPtr: FFIPointer- The pointer to the function.
Throws
- FFI Error
- Memory Error
closure
closure(definition: -- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerType
export type FFIFunctionDefintion = {
returns: FFIAnyDataType,
args: {FFIAnyDataType}
}FFIFunctionDefintion-- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerType
export type FFIFunctionDefintion = {
returns: FFIAnyDataType,
args: {FFIAnyDataType}
}, handler: (...any) -> any): FFIPointerParameters
definition: FFIFunctionDefintion- The function definition.returns: FFIAnyDataType- The return type of the function.args: {FFIAnyDataType}- The argument types of the function.
handler: (...any) -> any- The lua function to call.
Throws
- FFI Error
- Memory Error
dlopen
dlopen(path: string, functions: {[string]: -- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerType
export type FFIFunctionDefintion = {
returns: FFIAnyDataType,
args: {FFIAnyDataType}
}FFIFunctionDefintion-- references:
-- (1) FFIDataType
-- (2) FFIStructureType
-- (3) FFIArrayType
-- (4) FFIPointerType
export type FFIAnyDataType = FFIDataType | FFIStructureType | FFIArrayType | FFIPointerType
export type FFIFunctionDefintion = {
returns: FFIAnyDataType,
args: {FFIAnyDataType}
}}): -- references:
-- (1) FFIPointer
export type FFILibrary = {
getSymbol: (self: FFILibrary, symbol: string) -> FFIPointer?,
[string]: (...any) -> any,
}FFILibrary-- references:
-- (1) FFIPointer
export type FFILibrary = {
getSymbol: (self: FFILibrary, symbol: string) -> FFIPointer?,
[string]: (...any) -> any,
}Parameters
path: string- The path to the library.functions: { [string]: FFIFunctionDefintion }- The symbols to load from the library.
Throws
- FFI Error
- Memory Error
Namespaces
c
FUNCTIONS
compile
c.compile(src: string, opts: -- references:
-- (1) FFIPointer
export type FFICompileOptions = {
options: string?,
files: {string}?,
libraries: {string}?,
library_paths: {string}?,
includes: {string}?,
sysincludes: {string}?,
symbols: {
[string]: FFIPointer
}?,
}FFICompileOptions-- references:
-- (1) FFIPointer
export type FFICompileOptions = {
options: string?,
files: {string}?,
libraries: {string}?,
library_paths: {string}?,
includes: {string}?,
sysincludes: {string}?,
symbols: {
[string]: FFIPointer
}?,
}?): FFICompiledParameters
src: string- The C source code to compile.opts: FFICompileOptions?- The options for the compilation.options: string?- The compiler options to use.files: {string}?- The files to include in the compilation.libraries: {string}?- The libraries to link against.library_paths: {string}?- The library paths to use.includes: {string}?- The include directories to use.sysincludes: {string}?- The system include directories to use.symbols: {[string]: FFIPointer}?- The symbols to define.
Last updated on