@yuuang/ffi-rs-linux-arm64-musl
Advanced tools
Comparing version 1.0.47 to 1.0.48
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
728
611271
2