Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ffi-rs replace ffi-napi #257 #642

Open
zhangyuang opened this issue Aug 13, 2023 · 1 comment
Open

Use ffi-rs replace ffi-napi #257 #642

zhangyuang opened this issue Aug 13, 2023 · 1 comment

Comments

@zhangyuang
Copy link

https://github.com/zhangyuang/node-ffi-rs
Hi, there a is a module named ffi-rs written in Rust and N-API that provides FFI (Foreign Function Interface) features for Node.js

It allows developers to call functions written in other languages such as C++, C, and Rust directly from JavaScript without writing any C++ code.

This module aims to provide similar functionality to the node-ffi module, but with a completely rewritten underlying codebase. The node-ffi module has been unmaintained for several years and is no longer usable, which is why ffi-rs was developed.

const { equal } = require('assert')
const { load, RetType, ParamsType } = require('ffi-rs')
const a = 1
const b = 100

const r = load({
  library: "./libsum.so", // path to the dynamic library file
  funcName: 'sum', // the name of the function to call
  retType: RetType.I32, // the return value type
  paramsType: [ParamsType.I32, ParamsType.I32], // the parameter types
  paramsValue: [a, b] // the actual parameter values
})

equal(r, a + b)

const c = "foo"
const d = "bar"

equal(c + d, load({
  library: dynamicLib,
  funcName: 'concatenateStrings',
  retType: RetType.String,
  paramsType: [ParamsType.String, ParamsType.String],
  paramsValue: [c, d]
}))

equal(undefined, load({
  library: dynamicLib,
  funcName: 'noRet',
  retType: RetType.Void,
  paramsType: [],
  paramsValue: []
}))
@zhangyuang zhangyuang changed the title The new library by rust and napi for node.js ffi The new library ffi-rs written by rust and napi for node.js ffi Aug 13, 2023
@lotricLohale
Copy link

牛啊,老哥

@zhangyuang zhangyuang changed the title The new library ffi-rs written by rust and napi for node.js ffi Use ffi-rs replace ffi-napi #257 Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants