Dynamic module ffi

Index

Variables

Functions

Variables

CIF: (retType: any, types: any[], abi?: any) => Buffer

CIF_var: (retType: any, types: any[], numFixedArgs: number, abi?: any) => Buffer

Callback: { (retType: any, argTypes: any[], abi: number, fn: any): Buffer; (retType: any, argTypes: any[], fn: any): Buffer; new(retType: any, argTypes: any[], abi: number, fn: any): Buffer; new(retType: any, argTypes: any[], fn: any): Buffer; }

Turns a JavaScript function into a C function pointer. The function pointer may be used in other C functions that accept C callback functions.

(): Buffer

Returns

Buffer

(): Buffer

Returns

Buffer

constructor(): Buffer

Returns

Buffer

constructor(): Buffer

Returns

Buffer

DynamicLibrary: DynamicLibrary

This class loads and fetches function pointers for dynamic libraries (.so, .dylib, etc). After the libray's function pointer is acquired, then you call get(symbol) to retreive a pointer to an exported symbol. You need to call get___ on the pointer to dereference it into its actual value, or turn the pointer into a callable function with ForeignFunction.

public close(): number

Close library, returns the result of the dlclose system function.

Returns

number

public error(): string

Get the result of the dlerror system function.

Returns

string

public get(symbol: string): Buffer

Get a symbol from this library.

Parameters

  • symbol: string

Returns

Buffer

FFI_BAD_ABI: number

FFI_BAD_TYPEDEF: number

FFI_DEFAULT_ABI: number

FFI_FIRST_ABI: number

FFI_LAST_ABI: number

FFI_OK: number

FFI_SYSV: number

FFI_TYPE: StructType

FFI_TYPES: { [key: string]: Buffer; }

(): Buffer

Returns

Buffer

FFI_UNIX64: number

ForeignFunction: ForeignFunction

Represents a foreign function in another library. Manages all of the aspects of function execution, including marshalling the data parameters for the function into native types and also unmarshalling the return from function execution.

(args?: Array<any>): any

Parameters

  • args?: Array<any> optional

Returns

any

public async(args?: Array<any>)

Parameters

  • args?: Array<any> optional

Function: Function

Creates and returns a type for a C function pointer.

public abi: number

optional public alignment?: number

The alignment of this datatype when placed inside a struct.

public argTypes: Type[]

The type of arguments.

public ffi_type: Buffer

Is set for node-ffi functions.

public indirection: number

The current level of indirection of the buffer.

optional public name?: string

The name to use during debugging for this datatype.

public retType: Type

The type of return value.

public size: number

The size in bytes required to hold this datatype.

public get(buffer: Buffer, offset: number): any

To invoke when ref.get is invoked on a buffer of this type.

Parameters

  • buffer: Buffer
  • offset: number

Returns

any

public set(buffer: Buffer, offset: number, value: any)

To invoke when ref.set is invoked on a buffer of this type.

Parameters

  • buffer: Buffer
  • offset: number
  • value: any

public toFunction(buf: Buffer): ForeignFunction

Get a ForeignFunction of this function type.

Parameters

Returns

ForeignFunction

public toPointer(fn: (...args: any[]) => any): Buffer

Get a Callback pointer of this function type.

Parameters

  • fn: (...args: any[]) => any

Returns

Buffer

HAS_OBJC: boolean

LIB_EXT: string

Library: { EXT: string; (libFile: string, funcs?: { [key: string]: any[]; }, lib?: Object): any; new(libFile: string, funcs?: { [key: string]: any[]; }, lib?: Object): any; }

Provides a friendly API on-top of DynamicLibrary and ForeignFunction.

(): any

Returns

any

constructor(): any

Returns

any

public Library.EXT: string

The extension to use on libraries.

RTLD_DEFAULT: Buffer

RTLD_GLOBAL: number

RTLD_LAZY: number

RTLD_LOCAL: number

RTLD_NEXT: Buffer

RTLD_NODELETE: number

RTLD_NOLOAD: number

RTLD_NOW: number

VariadicForeignFunction: VariadicForeignFunction

For when you want to call to a C function with variable amount of arguments. i.e. printf.

This function takes care of caching and reusing ForeignFunction instances that contain the same ffi_type argument signature.

(args?: Array<any>): ForeignFunction

What gets returned is another function that needs to be invoked with the rest of the variadic types that are being invoked from the function.

Parameters

  • args?: Array<any> optional

Returns

ForeignFunction

public returnType: any

Return type as a property of the function generator to allow for monkey patching the return value in the very rare case where the return type is variadic as well

ffiType: { FFI_TYPE: "ref-struct".StructType; (type: "ref".Type): Buffer; (type: string): Buffer; }

(): Buffer

Get a ffi_type * Buffer appropriate for the given type.

Returns

Buffer

(): Buffer

Get a ffi_type * Buffer appropriate for the given type.

Returns

Buffer

public ffiType.FFI_TYPE: StructType

types: { void: "ref".Type; int64: "ref".Type; ushort: "ref".Type; int: "ref".Type; uint64: "ref".Type; float: "ref".Type; uint: "ref".Type; long: "ref".Type; double: "ref".Type; int8: "ref".Type; ulong: "ref".Type; Object: "ref".Type; uint8: "ref".Type; longlong: "ref".Type; CString: "ref".Type; int16: "ref".Type; ulonglong: "ref".Type; bool: "ref".Type; uint16: "ref".Type; char: "ref".Type; byte: "ref".Type; int32: "ref".Type; uchar: "ref".Type; size_t: "ref".Type; uint32: "ref".Type; short: "ref".Type; }

Default types.

public types.CString: Type

public types.Object: Type

public types.bool: Type

public types.byte: Type

public types.char: Type

public types.double: Type

public types.float: Type

public types.int: Type

public types.int16: Type

public types.int32: Type

public types.int64: Type

public types.int8: Type

public types.long: Type

public types.longlong: Type

public types.short: Type

public types.size_t: Type

public types.uchar: Type

public types.uint: Type

public types.uint16: Type

public types.uint32: Type

public types.uint64: Type

public types.uint8: Type

public types.ulong: Type

public types.ulonglong: Type

public types.ushort: Type

public types.void: Type

Functions

errno(): number

Get value of errno.

Returns

number