Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@yuuang/ffi-rs-darwin-x64

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yuuang/ffi-rs-darwin-x64 - npm Package Compare versions

Comparing version 1.0.9 to 1.0.11

2

package.json
{
"name": "@yuuang/ffi-rs-darwin-x64",
"version": "1.0.9",
"version": "1.0.11",
"os": [

@@ -5,0 +5,0 @@ "darwin"

@@ -16,6 +16,14 @@ # ffi-rs

## Support type
Currently, ffi-rs only supports there types of parameters and return values. However, support for more types will be added in the future based on actual usage scenarios.
- string
- number(i32)
- void
- double
- i32Array
## Usage
Currently, ffi-rs only supports two types of parameters and return values: strings and numbers. However, support for more types will be added in the future based on actual usage scenarios.
Here is an example of how to use ffi-rs:

@@ -26,4 +34,11 @@

```cpp
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
extern "C" int sum(int a, int b) { return a + b; }
extern "C" double doubleSum(double a, double b) { return a + b; }
extern "C" const char *concatenateStrings(const char *str1, const char *str2) {

@@ -36,2 +51,15 @@ std::string result = std::string(str1) + std::string(str2);

extern "C" void noRet() { printf("%s", "hello world"); }
extern "C" int *createArrayi32(const int *arr, int size) {
int *vec = (int *)malloc((size) * sizeof(int));
for (int i = 0; i < size; i++) {
vec[i] = arr[i];
}
return vec;
}
```

@@ -52,2 +80,3 @@

const b = 100
const dynamicLib = platform === 'win32' ? './sum.dll' : "./libsum.so"

@@ -68,5 +97,5 @@ const r = load({

equal(c + d, load({
library: "./libsum.so",
library: dynamicLib,
funcName: 'concatenateStrings',
retType: ParamsType.String,
retType: RetType.String,
paramsType: [ParamsType.String, ParamsType.String],

@@ -76,3 +105,28 @@ paramsValue: [c, d]

equal(undefined, load({
library: dynamicLib,
funcName: 'noRet',
retType: RetType.Void,
paramsType: [],
paramsValue: []
}))
equal(1.1 + 2.2, load({
library: dynamicLib,
funcName: 'doubleSum',
retType: RetType.Double,
paramsType: [ParamsType.Double, ParamsType.Double],
paramsValue: [1.1, 2.2]
}))
let bigArr = new Array(100000).fill(100)
equal(Math.max(bigArr), Math.max(load({
library: dynamicLib,
funcName: 'createArrayi32',
retType: RetType.I32Array,
paramsType: [ParamsType.I32Array, ParamsType.I32],
paramsValue: [bigArr, bigArr.length],
retTypeLen: bigArr.length
})))
```

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