library.getFunction(name, signature)


解析一个符号并返回一个可调用的 JavaScript 封装器。

🌐 Resolves a symbol and returns a callable JavaScript wrapper.

返回的函数有一个 .pointer 属性,包含作为 bigint 的原生函数地址。

🌐 The returned function has a .pointer property containing the native function address as a bigint.

如果相同的符号已经被解析,再用不同的签名请求它会抛出异常。

🌐 If the same symbol has already been resolved, requesting it again with a different signature throws.

const { DynamicLibrary } = require('node:ffi');

const lib = new DynamicLibrary('./mylib.so');
const add = lib.getFunction('add_i32', {
  parameters: ['i32', 'i32'],
  result: 'i32',
});

console.log(add(20, 22));
console.log(add.pointer);