CType 编辑

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.
PointerType
These represent pointers to data in memory.
FunctionType
These represent callable C functions.
StructType
These represent C structures.
ArrayType
These represent C arrays.

Method overview

Methods available on all CType objects

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

Properties

Properties of all CType objects

These properties are available on all CType objects.

PropertyTypeDescription
nameString

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.

ptrCTypeReturns a CType representing the data type "pointer to this type". This is the result of calling ctypes.PointerType(the_type). Read only.
sizeNumber

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.

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.

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:98 次

字数:6027

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文