This doc is a work in progress.
ctypes object is the base of the ctypes API. It is obtained by by loading the ctypes module:
You can use the
ctypes object to load libraries, construct types, and perform miscellaneous tasks such as type casting. The
object also provides numerous predefined types that correspond to primitives and common typedefs in C.
Library object is used mostly to declare native functions provided by the library so that js-ctypes knows how to call them. See
Library.declare() for instructions on how to declare these functions.
Once you have finished working with a Library, call
To use js-ctypes effectively, it is important to understand the different kinds of objects that the module provides. There are three major categories:
These represent a type in C, and are thus represented by
CType objects. These objects have two main purposes. First, they provide a concrete representation of different data types, allowing the programmer to describe the arguments and return type of a native function (see
Library.declare()). Second, they serve as constructors to create concrete instances of the given type, i.e.
Out of the box, js-ctypes supports a number of predefined types.
These are functions that define new types, and thus return a
CType object. These include
.ptrproperty, which creates a new type describing a pointer to an existing type.
ctypes.ArrayType(type, [length])and the
.array()method, which creates a new type describing an array of objects of an existing type.
ctypes.StructType(), which creates a new type describing a C struct.
ctypes.FunctionType(abi, returnType, argType1 [, argType2 ...]), which creates a new type describing a C function.
These distinctions are crucial, and understanding them will alleviate much of the confusion surrounding js-ctypes. Calling a Type Constructor will return a
CType. Calling a
CType will return a
CData. You declare the arguments and return value of a native function with
CType objects. You call a native function with