Add node to Rust example
This commit is contained in:
4
node-to-rust/src/lib.rs
Normal file
4
node-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#[no_mangle]
|
||||
pub extern fn double_input(input: i32) -> i32 {
|
||||
input * 2
|
||||
}
|
||||
9
node-to-rust/src/main.js
Normal file
9
node-to-rust/src/main.js
Normal file
@@ -0,0 +1,9 @@
|
||||
var ffi = require('ffi');
|
||||
|
||||
var lib = ffi.Library('target/libdouble_input.so', {
|
||||
'double_input': [ 'int', [ 'int' ] ]
|
||||
});
|
||||
|
||||
var input = 4;
|
||||
var output = lib.double_input(input);
|
||||
console.log(input + " * 2 = " + output);
|
||||
Reference in New Issue
Block a user