-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNativeFromJavaScript.js
More file actions
28 lines (23 loc) · 922 Bytes
/
NativeFromJavaScript.js
File metadata and controls
28 lines (23 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const ffi = require("ffi-napi");
const ArrayType = require("ref-array-napi");
const DoubleArray = ArrayType("double");
const nativeLibrary = ffi.Library("/native-demo/native-c#.dll", {
print_message: ["void", []],
add_numbers: ["int", ["int", "int"]],
subtract_numbers: ["int", ["int", "int"]],
multiply_numbers: ["double", ["double", "double"]],
divide_numbers: ["double", ["double", "double"]],
populate_array: ["void", [DoubleArray, "int"]],
});
const added = nativeLibrary.add_numbers(7, 2);
const subtracted = nativeLibrary.subtract_numbers(7, 2);
const multiplied = nativeLibrary.multiply_numbers(7, 2);
const divided = nativeLibrary.divide_numbers(7, 2);
const array = new DoubleArray(5);
nativeLibrary.populate_array(array, array.length);
nativeLibrary.print_message();
console.log(added);
console.log(subtracted);
console.log(multiplied);
console.log(divided);
console.log(JSON.stringify(array));