node-ctypes - v2.17.1
    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 a native C++20/assembly FFI backend 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
    CField
    StructType
    ArrayType
    Array
    CDataAggregate
    Structure
    Union
    BigEndianStructure
    LittleEndianStructure
    BigEndianUnion
    LittleEndianUnion
    Callback
    ThreadSafeCallback
    Executor
    ArgumentError
    AttributeError
    CDLL
    FunctionOptions
    FFIFunction
    NativeFFIFunction
    TypedFFIFunction
    LibraryOptions
    FunctionWrapper
    FieldDef
    StructDef
    UnionDef
    BitFieldDef
    ArrayTypeDef
    ArrayProxy
    StructOptions
    AnonymousField
    DefinedClass
    CallbackWrapper
    ThreadSafeCallbackWrapper
    NativeCallbackContext
    ThreadSafeCallbackOptions
    CallbackOptions
    ExecutorOptions
    PointerInstance
    PointerTypeDef
    ByRefAddress
    CArgObject
    CharBufferValue
    WideBufferValue
    CTypeValues
    SimpleCDataInstance
    ParamFlag
    FuncPtrFactory
    FuncPtrOptions
    SimpleCDataConstructor
    ErrcheckCallback
    NativeErrcheckCallback
    LibraryNamespace
    CFieldsOf
    StructBuffer
    FieldEntry
    FieldSpec
    ArrayInstance
    NativeCallbackHook
    CallableCallback
    ExecutorTarget
    CharBuffer
    WideBuffer
    MemoryView
    ReadonlyMemoryView
    AnyType
    StructureClass
    FFIType
    JsFromCType
    JsArgFromCType
    JsFromTag
    JsArgFromTag
    StructureOf
    MemoryTarget
    IntegerArgument
    SwappedConstructor
    FFIFunction
    cdll
    LibraryLoader
    windll
    oledll
    util
    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_longdouble
    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
    byref
    POINTER
    SetPointerType
    pointer
    create_string_buffer
    c_buffer
    create_unicode_buffer
    string_at
    wstring_at
    memoryview_at
    resize
    addressof
    memmove
    memset
    readValue
    writeValue
    sizeof
    alignment
    get_errno
    set_errno
    GetLastError
    SetLastError
    get_last_error
    set_last_error
    FormatError
    WinError
    callback
    CFUNCTYPE
    cast