A Rust wrapper for QuickJS.
QuickJS is a new, small Javascript engine by Fabrice Bellard. It is fast and supports the full ES2019 specification (almost).
This crate allows you to easily run and integrate with Javascript code from Rust.
toml
[dependencies]
quick = "0.1.0-alpha.2"
```rust use quickjs::{Context, JsValue};
let context = quickjs::Context::new().unwrap();
// Eval.
let value = context.eval("1 + 2").unwrap(); assert_eq!(value, JsValue::Int(3));
let value = context.evalas::
// Callbacks.
context.add_callback("myCallback", |a: i32, b: i32| a + b).unwrap();
context.eval(r#" // x will equal 30 var x = myCallback(10, 20); "#).unwrap(); ```
By default, quickjs is bundled with the libquickjs-sys
crate and
automatically compiled, assuming you have the appropriate dependencies.
QuickJS will always be statically linked to your binary.
If you would like to use a system version instead, see below.
To use the system installation, without the bundled feature, first install the required dependencies, and then compile and install quickjs.
```bash
mkdir quickjs curl -L https://bellard.org/quickjs/quickjs-2019-07-09.tar.xz | tar xJv -C quickjs --strip-components 1 cd quickjs sudo make install ```
Then just add quickjs
as a dependency.
The obvious and preferred choices for the crate names would have been
quickjs-sys
and quickjs
.
Sadly, those crates were name-squatted without published code. Hence the less optimal names.