Library

  • Revision slug: Mozilla/js-ctypes/js-ctypes_reference/Library
  • Revision title: Library
  • Revision id: 109352
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment one or more formatting changes

Revision Content

{{ gecko_minversion_header("2.0") }}

{{ draft() }}

The Library object represents a native library loaded by the ctypes open() method. Its methods let you declare symbols exported by the library, and to manage the library.

Method overview

close();
CData declare(name, [abi, ], returnType[, argType1, ...]);

Methods

close()

Closes the library. You need to call this once you're done using the library.

close();
Parameters

None.

declare()

Declares an API from the native library, allowing it to be used from JavaScript. This can be used both for exported data symbols and for functions.

CData declare(
  name[,
  abi,
  returnType
  argType1,
  ...]
);
Parameters
name
The name of the symbol exported by the native library that is to be declared as usable from JavaScript
abi
The ABI used by the exported function; this will be ctypes.default_abi for most libraries, except for Windows libraries, which will be ctypes.winapi_abi or ctypes.stdcall_abi. See ABI constants. You don't need to provide this for exported data; it's only needed for function declarations.
returnType
The data type returned by the defined API, if it's a function. This parameter should not be provided if the API is an exported data symbol. For supported data types, see Data types.
argType1...argTypeN
Zero or more parameter types may be specified for the parameters of the function being declared. These should not be provided if the API is an exported data symbol rather than a function. For supported data types, see Data types.
Return value

A CData object representing the declared API.

Exceptions thrown
TypeError
The return type was specified as an array.

Revision Source

<p>{{ gecko_minversion_header("2.0") }}</p>
<p>{{ draft() }}</p>
<p>The <code>Library</code> object represents a native library loaded by the ctypes <a href="/en/js-ctypes/js-ctypes_reference/ctypes#open()" title="en/js-ctypes/js-ctypes reference/ctypes#open()"><code>open()</code></a> method. Its methods let you declare symbols exported by the library, and to manage the library.</p>
<h2 id="Method_overview">Method overview</h2>
<table class="standard-table"> <tbody> <tr> <td><code><a href="/en/js-ctypes/js-ctypes_reference/Library#close()" title="en/js-ctypes/js-ctypes reference/Library#close()">close</a>();</code></td> </tr> <tr> <td><code><a href="/en/js-ctypes/js-ctypes_reference/CData" title="en/js-ctypes/js-ctypes reference/CData">CData</a> <a href="/en/js-ctypes/js-ctypes_reference/Library#declare()" title="en/js-ctypes/js-ctypes reference/Library#declare()">declare</a>(name, [abi, ], returnType[, argType1, ...])</code>;</td> </tr> </tbody>
</table>
<h2 id="Methods">Methods</h2>
<h3 id="eatCookie.28.29" name="eatCookie.28.29">close()</h3>
<p>Closes the library. You need to call this once you're done using the library.</p>
<pre class="eval">close();
</pre>
<h6 id="Parameters" name="Parameters">Parameters</h6>
<p>None.</p>
<h3 id="eatCookie.28.29" name="eatCookie.28.29">declare()</h3>
<p>Declares an API from the native library, allowing it to be used from JavaScript. This can be used both for exported data symbols and for functions.</p>
<pre class="eval">CData declare(
  name[,
  abi,
  returnType
  argType1,
  ...]
);
</pre>
<h6 id="Parameters" name="Parameters">Parameters</h6>
<dl> <dt><code>name</code></dt> <dd>The name of the symbol exported by the native library that is to be declared as usable from JavaScript</dd> <dt><code>abi</code></dt> <dd>The ABI used by the exported function; this will be <code>ctypes.default_abi</code> for most libraries, except for Windows libraries, which will be <code>ctypes.winapi_abi</code> or <code>ctypes.stdcall_abi</code>. See <a href="/en/js-ctypes/js-ctypes_reference/ctypes#ABI_constants" title="en/js-ctypes/js-ctypes reference/ctypes#ABI constants">ABI constants</a>. You don't need to provide this for exported data; it's only needed for function declarations.</dd> <dt><code>returnType</code></dt> <dd>The data type returned by the defined API, if it's a function. This parameter should not be provided if the API is an exported data symbol. For supported data types, see <a href="/en/js-ctypes/js-ctypes_reference#Data_type_constants" title="en/js-ctypes/js-ctypes reference#Data type constants">Data types</a>.</dd> <dt><code>argType1...argTypeN</code></dt> <dd>Zero or more parameter types may be specified for the parameters of the function being declared. These should not be provided if the API is an exported data symbol rather than a function. For supported data types, see <a href="/en/js-ctypes/js-ctypes_reference#Data_type_constants" title="en/js-ctypes/js-ctypes reference#Data type constants">Data types</a>.</dd>
</dl>
<h6 id="Return_value">Return value</h6>
<p>A <a href="/en/js-ctypes/js-ctypes_reference/CData" title="en/js-ctypes/js-ctypes reference/CData"><code>CData</code></a> object representing the declared API.</p>
<h6 id="Exceptions_thrown">Exceptions thrown</h6>
<dl> <dt><code>TypeError</code></dt> <dd>The return type was specified as an array.</dd>
</dl>
Revert to this revision