Skip to content

Commit 5cef0dd

Browse files
committed
doc: use ffi.suffix for library paths in examples
Replace hardcoded .so library paths with ffi.suffix in the FFI documentation examples. Signed-off-by: Junsoo Ha <junsoo2018@naver.com>
1 parent b4bbb12 commit 5cef0dd

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

doc/api/ffi.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,20 @@ so it can be used with the [`using`][] declaration. Disposing the returned
202202
object closes the library handle.
203203

204204
```mjs
205-
import { dlopen } from 'node:ffi';
205+
import { dlopen, suffix } from 'node:ffi';
206206

207207
{
208-
using handle = dlopen('./mylib.so', {
208+
using handle = dlopen(`./mylib.${suffix}`, {
209209
add_i32: { arguments: ['i32', 'i32'], return: 'i32' },
210210
});
211211
console.log(handle.functions.add_i32(20, 22));
212212
} // handle.lib.close() is invoked automatically here.
213213
```
214214

215215
```mjs
216-
import { dlopen } from 'node:ffi';
216+
import { dlopen, suffix } from 'node:ffi';
217217

218-
const { lib, functions } = dlopen('./mylib.so', {
218+
const { lib, functions } = dlopen(`./mylib.${suffix}`, {
219219
add_i32: { arguments: ['i32', 'i32'], return: 'i32' },
220220
string_length: { arguments: ['pointer'], return: 'u64' },
221221
});
@@ -224,9 +224,9 @@ console.log(functions.add_i32(20, 22));
224224
```
225225

226226
```cjs
227-
const { dlopen } = require('node:ffi');
227+
const { dlopen, suffix } = require('node:ffi');
228228

229-
const { lib, functions } = dlopen('./mylib.so', {
229+
const { lib, functions } = dlopen(`./mylib.${suffix}`, {
230230
add_i32: { arguments: ['i32', 'i32'], return: 'i32' },
231231
string_length: { arguments: ['pointer'], return: 'u64' },
232232
});
@@ -278,9 +278,9 @@ Loads the dynamic library without resolving any functions eagerly.
278278
On Windows passing `null` is not supported.
279279

280280
```cjs
281-
const { DynamicLibrary } = require('node:ffi');
281+
const { DynamicLibrary, suffix } = require('node:ffi');
282282

283-
const lib = new DynamicLibrary('./mylib.so');
283+
const lib = new DynamicLibrary(`./mylib.${suffix}`);
284284
```
285285

286286
### `library.path`
@@ -310,10 +310,10 @@ library instance can be managed with the [`using`][] declaration. Leaving the
310310
enclosing scope invokes `library.close()` automatically.
311311

312312
```mjs
313-
import { DynamicLibrary } from 'node:ffi';
313+
import { DynamicLibrary, suffix } from 'node:ffi';
314314

315315
{
316-
using lib = new DynamicLibrary('./mylib.so');
316+
using lib = new DynamicLibrary(`./mylib.${suffix}`);
317317
// Use `lib` here; `lib.close()` is called when the block exits.
318318
}
319319
```
@@ -365,9 +365,9 @@ If the same symbol has already been resolved, requesting it again with a
365365
different signature throws.
366366

367367
```cjs
368-
const { DynamicLibrary } = require('node:ffi');
368+
const { DynamicLibrary, suffix } = require('node:ffi');
369369

370-
const lib = new DynamicLibrary('./mylib.so');
370+
const lib = new DynamicLibrary(`./mylib.${suffix}`);
371371
const add = lib.getFunction('add_i32', {
372372
arguments: ['i32', 'i32'],
373373
return: 'i32',
@@ -415,9 +415,9 @@ The return value is the callback pointer address as a `bigint`. It can be
415415
passed to native functions expecting a callback pointer.
416416

417417
```cjs
418-
const { DynamicLibrary } = require('node:ffi');
418+
const { DynamicLibrary, suffix } = require('node:ffi');
419419

420-
const lib = new DynamicLibrary('./mylib.so');
420+
const lib = new DynamicLibrary(`./mylib.${suffix}`);
421421

422422
const callback = lib.registerCallback(
423423
{ arguments: ['i32'], return: 'i32' },

0 commit comments

Comments
 (0)