CType

この記事はまだ日本語に翻訳されていません。MDN の翻訳はボランティアによって行われています。是非 MDN に登録し、私たちの力になって下さい。

Draft
This page is not complete.

All data types declared using the js-ctypes API are represented by CType objects. These objects have assorted methods and properties that let you create objects of these types, find out information about them, and so forth. The specific properties and methods on each object vary depending on the data type represented.

There are several kinds of types:

Primitive types
These are typical unstructured data, such as the predefined types listed in Predefined data types.
Big integer types
The Int64 and UInt64 types provide access to 64-bit integer values, which JavaScript doesn't currently support.
Pointer types
These represent pointers to data in memory.
Function types
These represent callable C functions.
Struct types
These represent C structures.
Array types
These represent C arrays.

Method overview

Methods available on all CType objects

CType array([n])
String toSource()
String toString()

Methods available on structure type objects

These methods are available only on CType objects representing structure types.

define(fields);

Properties

Properties of all CType objects

These properties are available on all CType objects.

Property Type Description
name String

The type's name. Read only.

For primitive types, this is just the name of the corresponding C type. For structure and opaque pointer types, this is simply the string that was passed to the constructor. For other function, pointer, and array types, this should be a valid C type expression.

ptr CType Returns a CType representing the data type "pointer to this type". This is the result of calling ctypes.PointerType(the_type). Read only.
size Number

The size of the type, in bytes. This is the same value as the C sizeof. Read only.

Note: ctypes.void_t.size is undefined.

Properties of pointer types

These properties are only available on pointer types.

Property Type Description
targetType CType The type of object the pointer points to.

Properties of function types

These properties are only available on function types.

Property Type Description
abi One of the ABI constants The ABI of the function. Read only.
argTypes
CType[] A sealed array of the argument types. Read only.
returnType
CType The return type of the function. Read only.

Properties of struct types

These properties are only available on struct types.

Property Type Description
fields CType[] A sealed array of field descriptors. Read only.

Properties of array types

These properties are only available on array types.

Property Type Description
elementType CType The data type of the elements in an array of this type. Read only.
length Number The number of elements in the array, or undefined if the array type doesn't have a specified length. Read only.

Methods available on all CType objects

array()

Returns a new CType representing an array of elements of the type on which it was called.

CType array(
  [n]
}; 
Parameters
n Optional
The number of elements in the declared array type. If this parameter is left out, the array's size is indeterminate.
Return value

A CType representing the data type "array of this type". This is the same as calling ctypes.ArrayType(the_type[, n]).

toSource()

Returns a JavaScript expression that evaluates to a CType describing the same C type as this object.

String toSource();
Parameters

None.

Return value

A JavaScript expression that evaluates to a CType describing the same C type as this object.

Example

ctypes.uint32_t.toSource() returns "ctypes.uint32_t".

toString()

Returns a string identifying the type. The format of this string is "type " + name.

String toString();
Parameters

None.

Return value

A string identifying the data type.

Methods available only on structure types

define()

Defines a previously declared opaque type's fields. This lets you convert an opaque structure type into a defined structure type.

define(
  fields
);
Parameters
fields
A field specification, as described under StructType().

Document Tags and Contributors

Contributors to this page: syssgx, Sheppy, kscarfone
最終更新者: Sheppy,