StructType
represents C structures.
Returns a CType object describing a new structure data type. This data type provides the ability to define and manipulate values of the C struct
type.
#pragma pack
).CType StructType( name[, fields] );
name
fields
Optionaldefine()
method to assign it a non-opaque type later. See Opaque structures for further explanation and an example.A CType object describing the newly created struct
data type.
TypeError
RangeError
size_t
and as a JavaScript Number.The fields
array is comprised of field descriptors, one for each field in the structure. Each field descriptor contains the field's name and its type, such as {'serialNumber': ctypes.int}
. A complete field descriptor list might look like this:
[ {'serialNumber': ctypes.int}, {'userName': ctypes.char.ptr} ]
Property | Type | Description |
fields |
CType[] |
A sealed array of field descriptors. Read only. |
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 Note:
ctypes.void_t.size is undefined. |
define(fields) |
CType array([n]) |
String toSource() |
String toString() |
Defines a previously declared opaque type's fields. This lets you convert an opaque structure type into a defined structure type.
define( fields );
CData structtype();
structtype
is StructType
CType
.A CData
representing the newly allocated struct.
Error
Every struct object has a getter and a setter for each member field of the structure.
Property | Type | Description |
constructor |
CType |
The data type of the Note: This is never
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. |
CData addressOfField(name) |
|
String toSource() |
String toString() |
Returns a new CData object of the appropriate pointer type, whose value points to the specified field of the structure on which the method was called. See Working with strings for more information on how to convert strings.
CData addressOfField( name );
name
A new CData object of the appropriate pointer type, whose value points to the contents of the specified field.
TypeError
name
is not a JavaScript string, or doesn't name a member field of the structure.