Revision 72694 of CType

  • Revision slug: Mozilla/js-ctypes/js-ctypes_reference/CType
  • Revision title: CType
  • Revision id: 72694
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment 72 words added, 21 words removed

Revision Content

{{ gecko_minversion_header("1.9.3") }}

{{ draft() }}

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.

Method overview

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

Properties

Properties of all CType objects

These properties are available on all CType objects.

Property Type Description
name String

The type's name.

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).
size Number The size of the type, in bytes. This is the same value as the C sizeof.

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, or null if it's an opaque pointer type. Read only.

Methods

array()

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

CType array(
  [n]
}; 
Parameters
n {{ optional_inline() }}
The number of elements in the declared array type.
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.

Revision Source

<p>{{ gecko_minversion_header("1.9.3") }}</p>
<p>{{ draft() }}</p>
<p>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.</p>
<h2>Method overview</h2>
<table class="standard-table"> <tbody> <tr> <td><span style="font-family: monospace;">CType array([n])</span><code><br> </code></td> </tr> <tr> <td><code>String toSource()</code></td> </tr> <tr> <td><code>String toString()</code></td> </tr> </tbody>
</table>
<h2>Properties</h2>
<h3>Properties of all CType objects</h3>
<p>These properties are available on all <code>CType</code> objects.</p>
<table class="standard-table" style="width: auto;"> <tbody> <tr> <td class="header">Property</td> <td class="header">Type</td> <td class="header">Description</td> </tr> <tr> <td><code>name</code></td> <td><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/String" title="en/Core JavaScript 1.5 Reference/Global Objects/String"><code>String</code></a></td> <td> <p>The type's name.</p> <p>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.</p> </td> </tr> <tr> <td><code>ptr</code></td> <td><code>CType</code></td> <td>Returns a <code>CType</code> representing the data type "pointer to this type". This is the result of calling <code>ctypes.PointerType(the_type)</code>.</td> </tr> <tr> <td><code>size</code></td> <td><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Number" title="en/Core JavaScript 1.5 Reference/Global Objects/Number"><code>Number</code></a></td> <td>The size of the type, in bytes. This is the same value as the C <code>sizeof</code>.</td> </tr> </tbody>
</table>
<h3>Properties of pointer types</h3>
<p>These properties are only available on pointer types.</p>
<table class="standard-table" style="width: auto;"> <tbody> <tr> <td class="header">Property</td> <td class="header">Type</td> <td class="header">Description</td> </tr> <tr> <td><code>targetType</code></td> <td><code>CType</code></td> <td>The type of object the pointer points to, or <code>null</code> if it's an opaque pointer type. <strong>Read only.</strong></td> </tr>  </tbody>
</table>
<h2>Methods</h2>
<h3>array()</h3>
<p>Returns a new <code>CType</code> representing an array of elements of the type on which it was called.</p>
<pre>CType array(
  [n]
}; 
</pre>
<h6>Parameters</h6>
<dl> <dt>n {{ optional_inline() }}</dt> <dd>The number of elements in the declared array type.</dd>
</dl>
<h6>Return value</h6>
<p>A <code>CType</code> representing the data type "array of this type". This is the same as calling <code>ctypes.ArrayType(the_type[, n])</code>.</p>
<h3>toSource()</h3>
<p>Returns a JavaScript expression that evaluates to a <code>CType</code> describing the same C type as this object.</p>
<pre>String toSource();
</pre>
<h6>Parameters</h6>
<p>None.</p>
<h6>Return value</h6>
<p>A JavaScript expression that evaluates to a <code>CType</code> describing the same C type as this object.</p>
<h6>Example</h6>
<p><code>ctypes.uint32_t.toSource()</code> returns "ctypes.uint32_t".</p>
<h3>toString()</h3>
<p>Returns a string identifying the type. The format of this string is "type " + <code>name</code>.</p>
<pre>String toString();
</pre>
<h6>Parameters</h6>
<p>None.</p>
<h6>Return value</h6>
<p>A string identifying the data type.</p>
Revert to this revision