Make API chainable.
This commit is contained in:
@@ -21,10 +21,10 @@ fn test_method_call() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
let mut engine = Engine::new();
|
||||
|
||||
engine.register_type::<TestStruct>();
|
||||
|
||||
engine.register_fn("update", TestStruct::update);
|
||||
engine.register_fn("new_ts", TestStruct::new);
|
||||
engine
|
||||
.register_type::<TestStruct>()
|
||||
.register_fn("update", TestStruct::update)
|
||||
.register_fn("new_ts", TestStruct::new);
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<TestStruct>("let x = new_ts(); x.update(1000); x")?,
|
||||
|
@@ -25,8 +25,10 @@ fn test_mismatched_op_custom_type() {
|
||||
}
|
||||
|
||||
let mut engine = Engine::new();
|
||||
engine.register_type_with_name::<TestStruct>("TestStruct");
|
||||
engine.register_fn("new_ts", TestStruct::new);
|
||||
|
||||
engine
|
||||
.register_type_with_name::<TestStruct>("TestStruct")
|
||||
.register_fn("new_ts", TestStruct::new);
|
||||
|
||||
assert!(matches!(
|
||||
*engine.eval::<INT>("60 + new_ts()").expect_err("should error"),
|
||||
|
@@ -69,6 +69,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut resolver = StaticModuleResolver::new();
|
||||
|
||||
let mut module = Module::new();
|
||||
|
||||
module.set_var("answer", 42 as INT);
|
||||
module.set_fn_4("sum".to_string(), |x: INT, y: INT, z: INT, w: INT| {
|
||||
Ok(x + y + z + w)
|
||||
|
@@ -3,16 +3,17 @@ use std::sync::{Arc, RwLock};
|
||||
|
||||
#[test]
|
||||
fn test_print() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
let logbook = Arc::new(RwLock::new(Vec::<String>::new()));
|
||||
|
||||
// Redirect print/debug output to 'log'
|
||||
let log = logbook.clone();
|
||||
engine.on_print(move |s| log.write().unwrap().push(format!("entry: {}", s)));
|
||||
let log1 = logbook.clone();
|
||||
let log2 = logbook.clone();
|
||||
|
||||
let log = logbook.clone();
|
||||
engine.on_debug(move |s| log.write().unwrap().push(format!("DEBUG: {}", s)));
|
||||
let mut engine = Engine::new();
|
||||
|
||||
engine
|
||||
.on_print(move |s| log1.write().unwrap().push(format!("entry: {}", s)))
|
||||
.on_debug(move |s| log2.write().unwrap().push(format!("DEBUG: {}", s)));
|
||||
|
||||
// Evaluate script
|
||||
engine.eval::<()>("print(40 + 2)")?;
|
||||
|
Reference in New Issue
Block a user