Socket
Socket
Sign inDemoInstall

@yuuang/ffi-rs-linux-arm64-musl

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yuuang/ffi-rs-linux-arm64-musl - npm Package Compare versions

Comparing version 1.0.47 to 1.0.48

2

package.json
{
"name": "@yuuang/ffi-rs-linux-arm64-musl",
"version": "1.0.47",
"version": "1.0.48",
"os": [

@@ -5,0 +5,0 @@ "linux"

@@ -72,2 +72,6 @@ # ffi-rs

### C++ Class
If you want to call c++ function, see [turorial](#c++)
## Support Platform

@@ -367,10 +371,10 @@

Similary, you can use `storePointer` to restore data from `pointer` which wrap by `createPointer`
Similary, you can use `restorePointer` to restore data from `pointer` which wrap by `createPointer`
```js
const external = createPointer({
const pointerArr = createPointer({
paramsType: [DataType.DoubleArray],
paramsValue: [[1.1, 2.2]]
})
const restoreData = storePointer({
const restoreData = restorePointer({
retType: [arrayConstructor({

@@ -380,3 +384,3 @@ type: DataType.DoubleArray,

})],
paramsValue: external
paramsValue: pointerArr
})

@@ -680,1 +684,48 @@ deepStrictEqual(restoreData, [[1.1, 2.2]])

Attention,since the vast majority of scenaros developers pass js function to c as a callback, so `ffi-rs` will create [threadsafe_function](https://nodejs.org/api/n-api.html#napi_threadsafe_function) from jsfunction which means the jsfunction will be called asynchronous, and Node.js process will not be exited automatically
## C++
We'll provide more examples from real-worl scenarios, if you have any ideas, please submit an issue
### class type
In C++ scene, we can use `DataType.External` to get class type pointer
In the code below, we use C types to wrap C++ types such as convert `char *` to `std::string` and return class pointer
```cpp
MyClass *createMyClass(std::string name, int age) {
return new MyClass(name, age);
}
extern "C" MyClass *createMyClassFromC(const char *name, int age) {
return createMyClass(std::string(name), age);
}
extern "C" void printMyClass(MyClass *instance) { instance->print(); }
```
And then, we can call it by above code
```js
const classPointer = load({
library: "libsum",
funcName: "createMyClassFromC",
retType: DataType.External,
paramsType: [
DataType.String,
DataType.I32
],
paramsValue: ["classString", 26],
});
load({
library: "libsum",
funcName: "printMyClass",
retType: DataType.External,
paramsType: [
DataType.External,
],
paramsValue: [classPointer],
})
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc