| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6794441 commit e655e42
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -202,20 +202,20 @@ so it can be used with the [`using`][] declaration. Disposing the returned | |||
| 202 | 202 | object closes the library handle. | |
| 203 | 203 | ||
| 204 | 204 | ```mjs | |
| 205 | - import { dlopen } from 'node:ffi'; | ||
| 205 | + import { dlopen, suffix } from 'node:ffi'; | ||
| 206 | 206 | ||
| 207 | 207 | { | |
| 208 | - using handle = dlopen('./mylib.so', { | ||
| 208 | + using handle = dlopen(`./mylib.${suffix}`, { | ||
| 209 | 209 | add_i32: { arguments: ['i32', 'i32'], return: 'i32' }, | |
| 210 | 210 | }); | |
| 211 | 211 | console.log(handle.functions.add_i32(20, 22)); | |
| 212 | 212 | } // handle.lib.close() is invoked automatically here. | |
| 213 | 213 | ``` | |
| 214 | 214 | ||
| 215 | 215 | ```mjs | |
| 216 | - import { dlopen } from 'node:ffi'; | ||
| 216 | + import { dlopen, suffix } from 'node:ffi'; | ||
| 217 | 217 | ||
| 218 | - const { lib, functions } = dlopen('./mylib.so', { | ||
| 218 | + const { lib, functions } = dlopen(`./mylib.${suffix}`, { | ||
| 219 | 219 | add_i32: { arguments: ['i32', 'i32'], return: 'i32' }, | |
| 220 | 220 | string_length: { arguments: ['pointer'], return: 'u64' }, | |
| 221 | 221 | }); | |
@@ -224,9 +224,9 @@ console.log(functions.add_i32(20, 22)); | |||
| 224 | 224 | ``` | |
| 225 | 225 | ||
| 226 | 226 | ```cjs | |
| 227 | - const { dlopen } = require('node:ffi'); | ||
| 227 | + const { dlopen, suffix } = require('node:ffi'); | ||
| 228 | 228 | ||
| 229 | - const { lib, functions } = dlopen('./mylib.so', { | ||
| 229 | + const { lib, functions } = dlopen(`./mylib.${suffix}`, { | ||
| 230 | 230 | add_i32: { arguments: ['i32', 'i32'], return: 'i32' }, | |
| 231 | 231 | string_length: { arguments: ['pointer'], return: 'u64' }, | |
| 232 | 232 | }); | |
@@ -278,9 +278,9 @@ Loads the dynamic library without resolving any functions eagerly. | |||
| 278 | 278 | On Windows passing `null` is not supported. | |
| 279 | 279 | ||
| 280 | 280 | ```cjs | |
| 281 | - const { DynamicLibrary } = require('node:ffi'); | ||
| 281 | + const { DynamicLibrary, suffix } = require('node:ffi'); | ||
| 282 | 282 | ||
| 283 | - const lib = new DynamicLibrary('./mylib.so'); | ||
| 283 | + const lib = new DynamicLibrary(`./mylib.${suffix}`); | ||
| 284 | 284 | ``` | |
| 285 | 285 | ||
| 286 | 286 | ### `library.path` | |
@@ -310,10 +310,10 @@ library instance can be managed with the [`using`][] declaration. Leaving the | |||
| 310 | 310 | enclosing scope invokes `library.close()` automatically. | |
| 311 | 311 | ||
| 312 | 312 | ```mjs | |
| 313 | - import { DynamicLibrary } from 'node:ffi'; | ||
| 313 | + import { DynamicLibrary, suffix } from 'node:ffi'; | ||
| 314 | 314 | ||
| 315 | 315 | { | |
| 316 | - using lib = new DynamicLibrary('./mylib.so'); | ||
| 316 | + using lib = new DynamicLibrary(`./mylib.${suffix}`); | ||
| 317 | 317 | // Use `lib` here; `lib.close()` is called when the block exits. | |
| 318 | 318 | } | |
| 319 | 319 | ``` | |
@@ -365,9 +365,9 @@ If the same symbol has already been resolved, requesting it again with a | |||
| 365 | 365 | different signature throws. | |
| 366 | 366 | ||
| 367 | 367 | ```cjs | |
| 368 | - const { DynamicLibrary } = require('node:ffi'); | ||
| 368 | + const { DynamicLibrary, suffix } = require('node:ffi'); | ||
| 369 | 369 | ||
| 370 | - const lib = new DynamicLibrary('./mylib.so'); | ||
| 370 | + const lib = new DynamicLibrary(`./mylib.${suffix}`); | ||
| 371 | 371 | const add = lib.getFunction('add_i32', { | |
| 372 | 372 | arguments: ['i32', 'i32'], | |
| 373 | 373 | return: 'i32', | |
@@ -415,9 +415,9 @@ The return value is the callback pointer address as a `bigint`. It can be | |||
| 415 | 415 | passed to native functions expecting a callback pointer. | |
| 416 | 416 | ||
| 417 | 417 | ```cjs | |
| 418 | - const { DynamicLibrary } = require('node:ffi'); | ||
| 418 | + const { DynamicLibrary, suffix } = require('node:ffi'); | ||
| 419 | 419 | ||
| 420 | - const lib = new DynamicLibrary('./mylib.so'); | ||
| 420 | + const lib = new DynamicLibrary(`./mylib.${suffix}`); | ||
| 421 | 421 | ||
| 422 | 422 | const callback = lib.registerCallback( | |
| 423 | 423 | { arguments: ['i32'], return: 'i32' }, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments