ArrayType 编辑
ArrayType
represents C arrays
Syntax
Returns a new CType representing an array data type.
CType ArrayType() type[ length] );
Parameters
Type: It represents the type of the elements or variable which is going to be present in an array
length
Optional- It denotes the number of entries present in an array or the number of elements that an array should contain. If you don't specify this parameter, the array's length is unspecified.
Return value
A CType represents the newly declared array type.
Exceptions thrown
TypeError
type
is not a CType, ortype.size
is undefined.If the length is specifed but if it is not a valid one,then it is also thrownRangeError
- The size of the resulting array can't be represented as both a
size_t
and as a JavaScript number.
Properties
Property | Type | Description |
elementType | CType | The data type of the elements in an array 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. |
Properties inherited from CType
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 ctypes.void_t.size is undefined. |
Method overview
Methods inherited from CType
CType array([n]) |
String toSource() |
String toString() |
ArrayType CData Syntax
CData sized_arraytype(); CData unsized_arraytype(length);
sized_arraytype
and unsized_arraytype
are ArrayType
CType.Parameters
length
- The number of entries the array type should be able to contain. Only for unsized
ArrayType
.
Return value
A CData representing the newly allocated array.
Exceptions thrown
TypeError
length
is not provided for unsized array, or is provided for sized array.
ArrayType CData Properties
Property | Type | Description |
length | Number | The length of the array. Read only. |
In addition, each element in the array can be referenced by index using standard bracket notation, such as myArray[index]
.
Properties inherited from CData
Property | Type | Description |
constructor | CType | The data type of the ctypes.void_t or an array type with an unspecified length. |
value | object | The JavaScript equivalent of the CData object's value. This will throw a TypeError exception if the value can't be converted. |
ArrayType CData Method_overview
CData addressOfElement(idx) |
Methods inherited from CData
|
String toSource() |
String toString() |
ArrayType CData Methods
addressOfElement()
Returns a new CData object of the appropriate pointer type, whose value points to the specified array element on which the method was called.
CData addressOfElement( idx );
Parameters
idx
- A numeric value indicating the offset into the array of the element just to return a pointer. If this value isn't a valid JavaScript number that's also a valid index into the array, a
TypeError
exception is thrown.
Return value
A new CData object pointing to the specified element.
The type of the returned object will be determined byctypes.PointerType(theArrayType.constructor.elementType))
.See Also
- CType
- CData
- Type conversion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论