[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/native-library](https://jsprismarine.dev/api/@jsprismarine/native-library/index.md) / ffi

# ffi

## Interfaces

### BoundLibrary

Defined in: [script-host/src/ffi.ts:60](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L60)

A bound library, its callbacks, and how to take a pointer to shared memory for it.

#### Properties

##### symbols

> `readonly` **symbols**: [`NativeSymbols`](#nativesymbols)

Defined in: [script-host/src/ffi.ts:61](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L61)

#### Methods

##### close()

> **close**(): `void`

Defined in: [script-host/src/ffi.ts:67](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L67)

###### Returns

`void`

##### pointerOf()

> **pointerOf**(`memory`): `bigint`

Defined in: [script-host/src/ffi.ts:66](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L66)

The address of a shared buffer's memory, which never moves while the buffer lives.

###### Parameters

###### memory

`SharedArrayBuffer`

###### Returns

`bigint`

##### registerHostCallback()

> **registerHostCallback**(`callback`): `bigint`

Defined in: [script-host/src/ffi.ts:63](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L63)

Makes a native function pointer that runs `callback` on this thread.

###### Parameters

###### callback

[`HostCallback`](#hostcallback)

###### Returns

`bigint`

##### unregisterHostCallback()

> **unregisterHostCallback**(`pointer`): `void`

Defined in: [script-host/src/ffi.ts:64](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L64)

###### Parameters

###### pointer

`bigint`

###### Returns

`void`

***

### BoundNative

Defined in: [ffi.ts:22](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L22)

A library opened with [bindNative](#bindnative).

#### Type Parameters

##### Symbols

`Symbols`

#### Properties

##### symbols

> `readonly` **symbols**: `Symbols`

Defined in: [ffi.ts:24](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L24)

One function per symbol; an optional symbol the library lacks is undefined.

#### Methods

##### close()

> **close**(): `void`

Defined in: [ffi.ts:31](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L31)

###### Returns

`void`

##### pointerOf()

> **pointerOf**(`memory`): [`NativePointer`](#nativepointer)

Defined in: [ffi.ts:30](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L30)

The address of a buffer's memory. It stays valid only while the buffer is alive and is
neither transferred nor resized, so keep it unchanged until native code is done with the
address.

###### Parameters

###### memory

`ArrayBufferLike`

###### Returns

[`NativePointer`](#nativepointer)

***

### BunFfi

Defined in: [script-host/src/ffi.ts:115](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L115)

The part of `bun:ffi` this binding uses.

#### Properties

##### JSCallback

> **JSCallback**: new (`callback`, `definition`) => `object`

Defined in: [script-host/src/ffi.ts:121](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L121)

###### Parameters

###### callback

(...`args`) => `number`

###### definition

###### args

`string`[]

###### returns

`string`

###### Returns

`object`

###### ptr

> `readonly` **ptr**: `number` \| `null`

###### close()

> **close**(): `void`

###### Returns

`void`

#### Methods

##### dlopen()

> **dlopen**(`path`, `definitions`): `object`

Defined in: [script-host/src/ffi.ts:116](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L116)

###### Parameters

###### path

`string`

###### definitions

`Record`\<`string`, \{ `args`: `string`[]; `returns`: `string`; \}\>

###### Returns

`object`

###### symbols

> **symbols**: `Record`\<`string`, (...`args`) => `unknown`\>

###### close()

> **close**(): `void`

###### Returns

`void`

##### ptr()

> **ptr**(`view`): `number`

Defined in: [script-host/src/ffi.ts:120](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L120)

###### Parameters

###### view

`Uint8Array`

###### Returns

`number`

***

### NativeSymbols

Defined in: [script-host/src/ffi.ts:14](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L14)

The C interface, one method per exported function.

#### Methods

##### jsh\_abi\_version()

> **jsh\_abi\_version**(): `number`

Defined in: [script-host/src/ffi.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L15)

###### Returns

`number`

##### jsh\_call()

> **jsh\_call**(`engine`, `fn`, `thisValue`, `length`): `number`

Defined in: [script-host/src/ffi.ts:33](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L33)

###### Parameters

###### engine

`bigint`

###### fn

`number`

###### thisValue

`number`

###### length

`number`

###### Returns

`number`

##### jsh\_context\_create()

> **jsh\_context\_create**(`engine`): `number`

Defined in: [script-host/src/ffi.ts:24](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L24)

###### Parameters

###### engine

`bigint`

###### Returns

`number`

##### jsh\_context\_select()

> **jsh\_context\_select**(`engine`, `context`): `number`

Defined in: [script-host/src/ffi.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L25)

###### Parameters

###### engine

`bigint`

###### context

`number`

###### Returns

`number`

##### jsh\_debug\_attach()

> **jsh\_debug\_attach**(`engine`, `context`, `pollLines`): `number`

Defined in: [script-host/src/ffi.ts:42](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L42)

###### Parameters

###### engine

`bigint`

###### context

`number`

###### pollLines

`number`

###### Returns

`number`

##### jsh\_debug\_describe()

> **jsh\_debug\_describe**(`engine`, `handle`): `number`

Defined in: [script-host/src/ffi.ts:52](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L52)

###### Parameters

###### engine

`bigint`

###### handle

`number`

###### Returns

`number`

##### jsh\_debug\_detach()

> **jsh\_debug\_detach**(`engine`): `void`

Defined in: [script-host/src/ffi.ts:43](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L43)

###### Parameters

###### engine

`bigint`

###### Returns

`void`

##### jsh\_debug\_evaluate()

> **jsh\_debug\_evaluate**(`engine`, `frame`, `source`, `length`): `number`

Defined in: [script-host/src/ffi.ts:51](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L51)

###### Parameters

###### engine

`bigint`

###### frame

`number`

###### source

`Uint8Array`

###### length

`number`

###### Returns

`number`

##### jsh\_debug\_exception()

> **jsh\_debug\_exception**(`engine`): `number`

Defined in: [script-host/src/ffi.ts:50](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L50)

###### Parameters

###### engine

`bigint`

###### Returns

`number`

##### jsh\_debug\_frames()

> **jsh\_debug\_frames**(`engine`): `number`

Defined in: [script-host/src/ffi.ts:48](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L48)

###### Parameters

###### engine

`bigint`

###### Returns

`number`

##### jsh\_debug\_pause()

> **jsh\_debug\_pause**(`engine`): `void`

Defined in: [script-host/src/ffi.ts:46](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L46)

###### Parameters

###### engine

`bigint`

###### Returns

`void`

##### jsh\_debug\_properties()

> **jsh\_debug\_properties**(`engine`, `handle`, `start`, `count`): `number`

Defined in: [script-host/src/ffi.ts:53](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L53)

###### Parameters

###### engine

`bigint`

###### handle

`number`

###### start

`number`

###### count

`number`

###### Returns

`number`

##### jsh\_debug\_resume()

> **jsh\_debug\_resume**(`engine`, `mode`): `number`

Defined in: [script-host/src/ffi.ts:47](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L47)

###### Parameters

###### engine

`bigint`

###### mode

`number`

###### Returns

`number`

##### jsh\_debug\_scope()

> **jsh\_debug\_scope**(`engine`, `frame`, `scope`): `number`

Defined in: [script-host/src/ffi.ts:49](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L49)

###### Parameters

###### engine

`bigint`

###### frame

`number`

###### scope

`number`

###### Returns

`number`

##### jsh\_debug\_set\_breakpoints()

> **jsh\_debug\_set\_breakpoints**(`engine`, `path`, `length`): `number`

Defined in: [script-host/src/ffi.ts:44](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L44)

###### Parameters

###### engine

`bigint`

###### path

`string`

###### length

`number`

###### Returns

`number`

##### jsh\_debug\_set\_stop\_on\_exception()

> **jsh\_debug\_set\_stop\_on\_exception**(`engine`, `stop`): `void`

Defined in: [script-host/src/ffi.ts:45](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L45)

###### Parameters

###### engine

`bigint`

###### stop

`number`

###### Returns

`void`

##### jsh\_decode()

> **jsh\_decode**(`engine`, `length`): `number`

Defined in: [script-host/src/ffi.ts:38](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L38)

###### Parameters

###### engine

`bigint`

###### length

`number`

###### Returns

`number`

##### jsh\_dup()

> **jsh\_dup**(`engine`, `handle`): `number`

Defined in: [script-host/src/ffi.ts:40](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L40)

###### Parameters

###### engine

`bigint`

###### handle

`number`

###### Returns

`number`

##### jsh\_encode()

> **jsh\_encode**(`engine`, `handle`): `number`

Defined in: [script-host/src/ffi.ts:39](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L39)

###### Parameters

###### engine

`bigint`

###### handle

`number`

###### Returns

`number`

##### jsh\_engine\_begin\_tick()

> **jsh\_engine\_begin\_tick**(`engine`): `void`

Defined in: [script-host/src/ffi.ts:28](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L28)

###### Parameters

###### engine

`bigint`

###### Returns

`void`

##### jsh\_engine\_create()

> **jsh\_engine\_create**(`host`, `buffer`, `capacity`, `memoryLimit`, `stackSize`): `bigint`

Defined in: [script-host/src/ffi.ts:16](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L16)

###### Parameters

###### host

`bigint`

###### buffer

`bigint`

###### capacity

`number`

###### memoryLimit

`number`

###### stackSize

`number`

###### Returns

`bigint`

##### jsh\_engine\_destroy()

> **jsh\_engine\_destroy**(`engine`): `void`

Defined in: [script-host/src/ffi.ts:23](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L23)

###### Parameters

###### engine

`bigint`

###### Returns

`void`

##### jsh\_engine\_set\_budget()

> **jsh\_engine\_set\_budget**(`engine`, `perCallback`, `perTick`): `void`

Defined in: [script-host/src/ffi.ts:27](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L27)

###### Parameters

###### engine

`bigint`

###### perCallback

`number`

###### perTick

`number`

###### Returns

`void`

##### jsh\_engine\_set\_buffer()

> **jsh\_engine\_set\_buffer**(`engine`, `buffer`, `capacity`): `void`

Defined in: [script-host/src/ffi.ts:26](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L26)

###### Parameters

###### engine

`bigint`

###### buffer

`bigint`

###### capacity

`number`

###### Returns

`void`

##### jsh\_engine\_stat()

> **jsh\_engine\_stat**(`engine`, `stat`): `number`

Defined in: [script-host/src/ffi.ts:29](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L29)

###### Parameters

###### engine

`bigint`

###### stat

`number`

###### Returns

`number`

##### jsh\_eval\_module()

> **jsh\_eval\_module**(`engine`, `name`, `source`, `length`): `number`

Defined in: [script-host/src/ffi.ts:31](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L31)

###### Parameters

###### engine

`bigint`

###### name

`string`

###### source

`Uint8Array`

###### length

`number`

###### Returns

`number`

##### jsh\_eval\_script()

> **jsh\_eval\_script**(`engine`, `name`, `source`, `length`): `number`

Defined in: [script-host/src/ffi.ts:30](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L30)

###### Parameters

###### engine

`bigint`

###### name

`string`

###### source

`Uint8Array`

###### length

`number`

###### Returns

`number`

##### jsh\_free()

> **jsh\_free**(`engine`, `handle`): `void`

Defined in: [script-host/src/ffi.ts:41](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L41)

###### Parameters

###### engine

`bigint`

###### handle

`number`

###### Returns

`void`

##### jsh\_get()

> **jsh\_get**(`engine`, `object`, `key`): `number`

Defined in: [script-host/src/ffi.ts:35](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L35)

###### Parameters

###### engine

`bigint`

###### object

`number`

###### key

`string`

###### Returns

`number`

##### jsh\_global()

> **jsh\_global**(`engine`): `number`

Defined in: [script-host/src/ffi.ts:34](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L34)

###### Parameters

###### engine

`bigint`

###### Returns

`number`

##### jsh\_host\_function()

> **jsh\_host\_function**(`engine`, `id`, `name`, `length`): `number`

Defined in: [script-host/src/ffi.ts:37](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L37)

###### Parameters

###### engine

`bigint`

###### id

`number`

###### name

`string`

###### length

`number`

###### Returns

`number`

##### jsh\_run\_jobs()

> **jsh\_run\_jobs**(`engine`, `context`): `number`

Defined in: [script-host/src/ffi.ts:32](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L32)

###### Parameters

###### engine

`bigint`

###### context

`number`

###### Returns

`number`

##### jsh\_set()

> **jsh\_set**(`engine`, `object`, `key`, `value`): `number`

Defined in: [script-host/src/ffi.ts:36](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L36)

###### Parameters

###### engine

`bigint`

###### object

`number`

###### key

`string`

###### value

`number`

###### Returns

`number`

***

### NodeFfi

Defined in: [ffi.ts:35](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L35)

The part of `node:ffi` this binding uses; Node.js 26 ships no types for it yet.

#### Methods

##### dlopen()

> **dlopen**(`path`, `definitions`): `object`

Defined in: [ffi.ts:36](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L36)

###### Parameters

###### path

`string`

###### definitions

`Record`\<`string`, \{ `arguments`: readonly `string`[]; `return`: `string`; \}\>

###### Returns

`object`

###### functions

> **functions**: `Record`\<`string`, (...`args`) => `unknown`\>

###### lib

> **lib**: `object`

###### lib.close()

> **close**(): `void`

###### Returns

`void`

###### lib.getFunction()

> **getFunction**(`name`, `definition`): (...`args`) => `unknown`

Binds one more symbol; throws when the library does not export it.

###### Parameters

###### name

`string`

###### definition

###### arguments

readonly `string`[]

###### return

`string`

###### Returns

(...`args`) => `unknown`

###### lib.registerCallback()

> **registerCallback**(`signature`, `callback`): `bigint`

Makes a native function pointer that runs `callback` on this thread.

###### Parameters

###### signature

###### arguments

readonly `string`[]

###### return

`string`

###### callback

(...`args`) => `number`

###### Returns

`bigint`

###### lib.unregisterCallback()

> **unregisterCallback**(`pointer`): `void`

###### Parameters

###### pointer

`bigint`

###### Returns

`void`

##### getRawPointer()

> **getRawPointer**(`memory`): `bigint`

Defined in: [ffi.ts:56](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L56)

###### Parameters

###### memory

`ArrayBufferLike`

###### Returns

`bigint`

## Type Aliases

### FfiKind

> **FfiKind** = `"i32"` \| `"f64"` \| `"void"` \| `"pointer"` \| `"buffer"`

Defined in: [ffi.ts:13](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L13)

An argument or result kind. `buffer` passes a typed array's memory by address for the length
of the call; `pointer` is an address the library returned.

***

### FfiSignature

> **FfiSignature** = readonly \[`result`: [`FfiKind`](#ffikind), `parameters`: readonly [`FfiKind`](#ffikind)[]\]

Defined in: [ffi.ts:16](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L16)

One symbol's C signature: its result, then its parameters in order.

***

### HostCallback

> **HostCallback** = (`op`, `id`, `length`) => `number`

Defined in: [script-host/src/ffi.ts:57](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L57)

The engine's callback: an operation, an id and a byte length in, a length or a status out.

#### Parameters

##### op

`number`

##### id

`number`

##### length

`number`

#### Returns

`number`

***

### NativePointer

> **NativePointer** = `bigint` \| `number`

Defined in: [ffi.ts:19](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L19)

A pointer the FFI hands to native code: a bigint under Node.js, a number under Bun.

***

### NativePointer

> **NativePointer** = `bigint`

Defined in: [script-host/src/ffi.ts:11](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L11)

A native address, as `node:ffi` passes one. The Bun binding converts its numbers to and from it.

## Functions

### bindBunLibrary()

> **bindBunLibrary**(`path`, `bun?`): [`BoundLibrary`](#boundlibrary)

Defined in: [script-host/src/ffi.ts:166](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L166)

Opens the library with `bun:ffi`.

#### Parameters

##### path

`string`

The shared library's file.

##### bun?

[`BunFfi`](#bunffi) = `...`

The `bun:ffi` module; a parameter so a test under Node.js can pass its own.

#### Returns

[`BoundLibrary`](#boundlibrary)

The bound library.

***

### bindLibrary()

> **bindLibrary**(`path`): [`BoundLibrary`](#boundlibrary)

Defined in: [script-host/src/ffi.ts:217](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/ffi.ts#L217)

Opens the library with the running runtime's FFI.

#### Parameters

##### path

`string`

The shared library's file.

#### Returns

[`BoundLibrary`](#boundlibrary)

The bound library.

#### Throws

When Node.js has no `node:ffi`.

#### Throws

When the library does not load.

***

### bindNative()

> **bindNative**\<`Symbols`\>(`path`, `signatures`, `optional?`): [`BoundNative`](#boundnative)\<`Symbols`\>

Defined in: [ffi.ts:126](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L126)

Opens a library with the running runtime's FFI.

#### Type Parameters

##### Symbols

`Symbols`

#### Parameters

##### path

`string`

The shared library's file.

##### signatures

`{ readonly [Name in string]: FfiSignature }`

Every symbol to bind, by name.

##### optional?

`ReadonlySet`\<`string`\> = `...`

Symbols a library built from older sources may lack; each stays undefined
  when it is missing, where a missing required symbol fails the load.

#### Returns

[`BoundNative`](#boundnative)\<`Symbols`\>

The bound library.

#### Throws

When Node.js has no `node:ffi`.

#### Throws

When the library does not load or lacks a required symbol.

***

### nodeFfi()

> **nodeFfi**(): [`NodeFfi`](#nodeffi)

Defined in: [ffi.ts:101](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L101)

Loads `node:ffi` without its experimental warning, which would otherwise print on every start.
Only that one warning is held back. A binding that needs more than [bindNative](#bindnative) gives,
such as callbacks, opens its library with this.

#### Returns

[`NodeFfi`](#nodeffi)

The module.

#### Throws

When the runtime has no `node:ffi`.

***

### nodeFfiOf()

> **nodeFfiOf**(`ffi`, `version`): [`NodeFfi`](#nodeffi)

Defined in: [ffi.ts:88](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/ffi.ts#L88)

The `node:ffi` module as this file calls it.

`process.getBuiltinModule` answers undefined on a Node.js built without FFI or started with
`--no-experimental-ffi`, which would otherwise fail later at `dlopen` with a TypeError that
names nothing.

#### Parameters

##### ffi

`unknown`

What the runtime answered for `node:ffi`.

##### version

`string`

The running Node.js version, for the message.

#### Returns

[`NodeFfi`](#nodeffi)

The module.

#### Throws

When the runtime has no `node:ffi`.
