Declaring types

  • Revision slug: Mozilla/js-ctypes/Using_js-ctypes/Declaring_types
  • Revision title: Declaring types
  • Revision id: 73086
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment getting started; checkpoint save; page created, 138 words added

Revision Content

{{ gecko_minversion_header("2.0") }}{{ draft() }}

The ctypes object offers a number of constructor methods that let you declare types. Every type is represented by a CType object, which, in turn, provides a constructor method you can call to define values of those types.

Types are declared in terms of other, already defined types. At the core of all this is a set of predefined types provided by js-ctypes.

Primitive types

Primitive types are those types that represent a single value in memory, as opposed to arrays, structures, or functions.

For example, on Windows, you may wish to be able to use the Windows-standard DWORD type name for unsigned 32-bit integers. To declare this type, you can simply do:

const DWORD = ctypes.uint32_t;

After doing this, DWORD is a CType that contains a single 32-bit unsigned integer.

Revision Source

<p>{{ gecko_minversion_header("2.0") }}{{ draft() }}</p>
<p>The <code><a href="/en/js-ctypes/js-ctypes_reference/ctypes" title="en/js-ctypes/js-ctypes reference/ctypes">ctypes</a></code> object offers a number of constructor methods that let you declare types. Every type is represented by a <a href="/en/js-ctypes/js-ctypes_reference/CType" title="en/js-ctypes/js-ctypes reference/CType"><code>CType</code></a> object, which, in turn, provides a constructor method you can call to define values of those types.</p>
<p>Types are declared in terms of other, already defined types. At the core of all this is a set of <a href="/en/js-ctypes/js-ctypes_reference/ctypes#Predefined_data_types" title="en/js-ctypes/js-ctypes reference/ctypes#Predefined data types">predefined types</a> provided by js-ctypes.</p>
<h2>Primitive types</h2>
<p><strong>Primitive types</strong> are those types that represent a single value in memory, as opposed to arrays, structures, or functions.</p>
<p>For example, on Windows, you may wish to be able to use the Windows-standard <code>DWORD</code> type name for unsigned 32-bit integers. To declare this type, you can simply do:</p>
<pre>const DWORD = ctypes.uint32_t;
</pre>
<p>After doing this, <code>DWORD</code> is a <a href="/en/js-ctypes/js-ctypes_reference/CType" title="en/js-ctypes/js-ctypes reference/CType"><code>CType</code></a> that contains a single 32-bit unsigned integer.</p>
Revert to this revision