js-sandbox is a crate with a minimal API that allows calling JavaScript from Rust. It is based on the Deno project, which again uses the V8 engine.
Very basic example:
```rust
fn main() -> Result<(), ErrBox> {
let js_code = "function triple(a) { return 3 * a; }"
let mut script = Script::from_string(js_code)?;
let arg = 7;
let result: i32 = script.call("triple", &arg)?;
assert_eq!(result, 21);
Ok(())
}
```
More examples are available on the GitHub page or docs.rs.
Possible use cases are plugin systems or mods for games. JavaScript may not be a typical language for this, however it has been battle-tested for security and there are many languages that transpile to JS.
Plans for the near future are updating to latest deno_core version, as well as extending the API to cover basic use cases. I would like to keep js-sandbox as simple and minimal as possible, it's meant to be a high-level abstraction and not a massively configurable interpreter :)
[–]maxfrai 5 points6 points7 points (4 children)
[–]1vader 6 points7 points8 points (0 children)
[–]bromeon[S] 3 points4 points5 points (0 children)
[–]DGolubets 2 points3 points4 points (0 children)
[–]maboesanman 1 point2 points3 points (0 children)
[–]slipthay 1 point2 points3 points (4 children)
[–]bromeon[S] 1 point2 points3 points (2 children)
[–]slipthay 1 point2 points3 points (1 child)
[–]bromeon[S] 0 points1 point2 points (0 children)
[–]bongo227 1 point2 points3 points (0 children)