I am writing a calculator in rust that uses js-sandbox to allow user-scripting for custom functions in javascript
I have a function that takes a mutable reference to an i32 and returns an Option in case of error, I call it run_js
I want to create a variable js_out and pass the reference to run_js, and print it out to prove that the function ran properly
I also have a main.js file with the function fibonacci which I tested, and it works with nodejs
I am getting the error: `let *output = script.call("fibonacci", &arg)?; expected pattern``
main.rs
use js_sandbox::{Script, AnyError};
fn run_js(sname: &str, output: &mut i32) -> Result<(), AnyError> {
let mut script = Script::from_file(sname).expect("File can be loaded");
let arg = 6;
let *output = script.call("fibonacci", &arg)?;
Ok(())
}
fn main() -> Result<(), AnyError> {
println!("SCalc version 0.1.0");
let mut js_out: i32 = 0;
run_js("src/main.js", &mut js_out)?;
println!("output: {}", js_out);
Ok(())
}
main.js
function fibonacci(length, startNums=[0, 1]) {
for (var i = 1; i < length-1; i++) {
startNums.push(startNums[i-1]+startNums[i]);
}
return startNums[startNums.length-1];
}
console.log(fibonacci(6));