node-ctypes - v2.10.0
    Preparing search index...

    Module index

    node-ctypes - Python ctypes-like FFI for Node.js

    A foreign function interface library that mirrors the Python ctypes API, built on libffi and N-API.

    import { CDLL, c_int } from 'node-ctypes';

    const libc = new CDLL('libc.so.6'); // Linux
    // const libc = new CDLL('msvcrt.dll'); // Windows
    // const libc = new CDLL('libc.dylib'); // macOS
    const abs_func = libc.abs;
    abs_func.argtypes = [c_int];
    abs_func.restype = c_int;
    console.log(abs_func(-42)); // 42
    import { Structure, c_int } from 'node-ctypes';

    class Point extends Structure {
    static _fields_ = [["x", c_int], ["y", c_int]];
    }

    const p = new Point(10, 20);
    console.log(p.x, p.y); // 10 20
    import { callback, c_int32, c_void_p, readValue } from 'node-ctypes';

    const compare = callback(
    (a, b) => readValue(a, c_int32) - readValue(b, c_int32),
    c_int32, [c_void_p, c_void_p]
    );
    // Pass compare.pointer to native functions
    compare.release(); // Release when done
    import { POINTER, pointer, c_int32 } from 'node-ctypes';

    const x = new c_int32(42);
    const p = pointer(x);
    console.log(p.contents.value); // 42
    Version
    Library
    WinDLL
    OleDLL
    StructType
    ArrayType
    Structure
    Union
    BigEndianStructure
    LittleEndianStructure
    BigEndianUnion
    LittleEndianUnion
    Callback
    ThreadSafeCallback
    ArgumentError
    CDLL
    FunctionOptions
    FFIFunction
    NativeFFIFunction
    TypedFFIFunction
    LibraryOptions
    FunctionWrapper
    FieldDef
    StructDef
    UnionDef
    BitFieldDef
    ArrayTypeDef
    ArrayProxy
    StructOptions
    AnonymousField
    DefinedClass
    CallbackWrapper
    ThreadSafeCallbackWrapper
    NativeCallbackContext
    ThreadSafeCallbackOptions
    PointerInstance
    PointerTypeDef
    ByRefAddress
    CharBufferValue
    WideBufferValue
    CTypeValues
    SimpleCDataConstructor
    SimpleCDataInstance
    ParamFlag
    FuncPtrFactory
    CharSlice
    ErrcheckCallback
    NativeErrcheckCallback
    LibraryNamespace
    FieldEntry
    FieldSpec
    ArrayInstance
    NativeCallbackHook
    CallableCallback
    CallbackRestype
    CastSource
    AnyType
    StructureClass
    FFIType
    JsFromCType
    JsArgFromCType
    JsFromTag
    JsArgFromTag
    StructureOf
    FieldsToInstance
    IsAny
    FieldsObject
    FieldsInput
    FieldValue
    FieldArg
    ArrayElement
    ArrayElementArg
    PointerValue
    PointerContents
    CharArrayValue
    ElementMethod
    ArgsFromCTypes
    JsArgFromFFIType
    FFIArgs
    FFIReturn
    CallbackArgs
    CallbackResult
    MemoryTarget
    MemorySource
    ArrayElementType
    W_BYTE
    W_WORD
    W_DWORD
    W_LONG
    W_SHORT
    W_HANDLE
    W_RECT
    W_POINT
    W_SIZE
    W_SMALL_RECT
    W_FILETIME
    W_MSG
    W_FIND_DATA
    cdll
    LibraryLoader
    windll
    oledll
    CType
    c_void
    c_int
    c_uint
    c_int8
    c_uint8
    c_int16
    c_uint16
    c_int32
    c_uint32
    c_int64
    c_uint64
    c_float
    c_double
    c_char
    c_char_p
    c_wchar
    c_wchar_p
    c_void_p
    c_bool
    c_size_t
    c_ssize_t
    c_long
    c_ulong
    c_byte
    c_ubyte
    c_short
    c_ushort
    c_longlong
    c_ulonglong
    c_voidp
    c_time_t
    wintypes
    SimpleCData
    POINTER_SIZE
    EXTERNAL_BUFFERS
    WCHAR_SIZE
    NULL
    SIZEOF_TIME_T
    RTLD_GLOBAL
    RTLD_LOCAL
    DEFAULT_MODE
    HRESULT
    load
    find_library
    struct
    union
    defineStruct
    defineUnion
    array
    ARRAY
    bitfield
    threadSafeCallback
    WINFUNCTYPE
    POINTER
    pointer
    create_string_buffer
    c_buffer
    create_unicode_buffer
    string_at
    wstring_at
    addressof
    memmove
    memset
    readValue
    writeValue
    sizeof
    alignment
    get_errno
    set_errno
    GetLastError
    SetLastError
    get_last_error
    set_last_error
    FormatError
    WinError
    callback
    CFUNCTYPE
    byref
    cast