Implement print/debug functions via Dynamic parameters.

This commit is contained in:
Stephen Chung
2021-02-23 19:08:05 +08:00
parent ba2b0630f7
commit 36420f0b99
4 changed files with 173 additions and 142 deletions

View File

@@ -1,6 +1,33 @@
use rhai::{Engine, EvalAltResult, RegisterFn, INT};
use rhai::{Engine, EvalAltResult, RegisterFn, Scope, INT};
use std::sync::{Arc, RwLock};
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
#[test]
fn test_to_string() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
let mut scope = Scope::new();
scope.push("x", 42_u8);
scope.push("y", 42_i32);
scope.push("z", 42_i16);
assert_eq!(
engine.eval_with_scope::<String>(&mut scope, "x.to_string()")?,
"42"
);
assert_eq!(
engine.eval_with_scope::<String>(&mut scope, "y.to_string()")?,
"42"
);
assert_eq!(
engine.eval_with_scope::<String>(&mut scope, "z.to_string()")?,
"42"
);
Ok(())
}
#[test]
fn test_print_debug() -> Result<(), Box<EvalAltResult>> {
let logbook = Arc::new(RwLock::new(Vec::<String>::new()));