Safe(er) rust wrapper for dukbind.
This library is a work in progress and is currently limited in features.
At the moment, duktape-rs
[x] Supports handling (what I assume to be) most JS errors that crop up during eval minimally tested
*Safety not guaranteed
For some reason docs.rs has a problem with compiling dukbind and won't generate them :/ Check back another time for documentation Coming Soon™
extern crate duktape-rs;
use duktape-rs::DukContext;
fn main() {
// Create a new context
let mut ctx = DukContext::new();
// Eval 5+5
let val = ctx.eval_string("5+5").unwrap();
// Destroy the heap (do this when you are done using the context)
ctx.destroy();
// Compare the value as an i64 against 10
assert_eq!(val.as_i64().expect("Not an i64"), 10)
}
Objects in duktape are returned as heap pointers that have to be stored and returned as a wrapper around that pointer.
let mut ctx = DukContext::new();
let obj = ctx.eval_string("({ok: true})").unwrap().as_object().expect("Not an object");
let val = obj.get_prop("ok").unwrap().as_bool().expect("Not a bool");
println!("Value: {}", val); //-> Value: true