Change Engine::consume_XXX to Engine::run_XXX.
This commit is contained in:
parent
e0125a1033
commit
180ad77224
@ -7,6 +7,7 @@ Version 1.1.0
|
||||
Enhancements
|
||||
------------
|
||||
|
||||
* `Engine::consume_XXX` methods are renamed to `Engine::run_XXX` to make meanings clearer. The `consume_XXX` API is deprecated.
|
||||
* `$symbol$` is supported in custom syntax to match any symbol.
|
||||
* Custom syntax with `$block$`, `}` or `;` as the last symbol are now self-terminating (i.e. no need to attach a terminating `;`).
|
||||
* `Dynamic::as_string` and `Dynamic::as_immutable_string` are deprecated and replaced by `into_string` and `into_immutable_string` respectively.
|
||||
|
@ -15,7 +15,7 @@ fn bench_eval_array_small_get(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -27,7 +27,7 @@ fn bench_eval_array_small_set(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -43,7 +43,7 @@ fn bench_eval_array_large_get(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -59,7 +59,7 @@ fn bench_eval_array_large_set(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -83,5 +83,5 @@ fn bench_eval_array_loop(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ fn bench_eval_expression_single(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -27,7 +27,7 @@ fn bench_eval_expression_number_literal(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -39,7 +39,7 @@ fn bench_eval_expression_number_operators(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -56,7 +56,7 @@ fn bench_eval_expression_optimized_simple(bench: &mut Bencher) {
|
||||
engine.set_optimization_level(OptimizationLevel::Simple);
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -73,7 +73,7 @@ fn bench_eval_expression_optimized_full(bench: &mut Bencher) {
|
||||
engine.set_optimization_level(OptimizationLevel::Full);
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -120,7 +120,7 @@ fn bench_eval_loop_number(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -137,7 +137,7 @@ fn bench_eval_loop_strings_build(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -154,7 +154,7 @@ fn bench_eval_loop_strings_no_build(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -186,7 +186,7 @@ fn bench_eval_switch(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -216,5 +216,5 @@ fn bench_eval_nested_if(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ fn bench_eval_map_small_get(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -27,7 +27,7 @@ fn bench_eval_map_small_set(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -47,7 +47,7 @@ fn bench_eval_map_large_get(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -67,5 +67,5 @@ fn bench_eval_map_large_set(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ fn bench_eval_module(bench: &mut Bencher) {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -49,5 +49,5 @@ fn bench_eval_function_call(bench: &mut Bencher) {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn bench_eval_scope_single(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -34,7 +34,7 @@ fn bench_eval_scope_multiple(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -50,7 +50,7 @@ fn bench_eval_scope_longer(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -73,5 +73,5 @@ fn bench_eval_scope_complex(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile_expression(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ fn bench_type_field(bench: &mut Bencher) {
|
||||
let mut scope = Scope::new();
|
||||
scope.push("foo", Test { x: 42 });
|
||||
|
||||
bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -59,7 +59,7 @@ fn bench_type_method(bench: &mut Bencher) {
|
||||
let mut scope = Scope::new();
|
||||
scope.push("foo", Test { x: 42 });
|
||||
|
||||
bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -77,7 +77,7 @@ fn bench_type_method_with_params(bench: &mut Bencher) {
|
||||
let mut scope = Scope::new();
|
||||
scope.push("foo", Test { x: 42 });
|
||||
|
||||
bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -96,5 +96,5 @@ fn bench_type_method_nested(bench: &mut Bencher) {
|
||||
let mut scope = Scope::new();
|
||||
scope.push("foo", Test { x: 42 });
|
||||
|
||||
bench.iter(|| engine.consume_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ fn bench_iterations_1000(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
@ -39,5 +39,5 @@ fn bench_eval_primes(bench: &mut Bencher) {
|
||||
|
||||
let ast = engine.compile(SCRIPT).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
bench.iter(|| engine.run_ast(&ast).unwrap());
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use rhai::{Engine, EvalAltResult, INT};
|
||||
fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
engine.consume(r#"print("hello, world!")"#)?;
|
||||
engine.run(r#"print("hello, world!")"#)?;
|
||||
|
||||
let result = engine.eval::<INT>("40 + 2")?;
|
||||
|
||||
|
@ -61,7 +61,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
println!("Line: {}", input.replace('\r', "\\r").replace('\n', "\\n"));
|
||||
|
||||
engine.consume_with_scope(
|
||||
engine.run_with_scope(
|
||||
&mut scope,
|
||||
r#"
|
||||
display("Length", x.len());
|
||||
|
@ -34,7 +34,7 @@ fn main() {
|
||||
|
||||
// Run script
|
||||
engine
|
||||
.consume(
|
||||
.run(
|
||||
r#"
|
||||
print("Starting script loop...");
|
||||
|
||||
|
@ -90,7 +90,7 @@ fn main() {
|
||||
.map_err(|err| err.into())
|
||||
.and_then(|mut ast| {
|
||||
ast.set_source(filename.to_string_lossy().to_string());
|
||||
engine.consume_ast(&ast)
|
||||
engine.run_ast(&ast)
|
||||
})
|
||||
{
|
||||
let filename = filename.to_string_lossy();
|
||||
|
@ -1906,7 +1906,7 @@ impl Dynamic {
|
||||
/// This method is deprecated. Use [`into_string`][Dynamic::into_string] instead.
|
||||
///
|
||||
/// This method will be removed in the next major version.
|
||||
#[deprecated(since = "1.0.1", note = "use `into_string` instead")]
|
||||
#[deprecated(since = "1.1.0", note = "use `into_string` instead")]
|
||||
#[inline(always)]
|
||||
pub fn as_string(self) -> Result<String, &'static str> {
|
||||
self.into_string()
|
||||
@ -1927,7 +1927,7 @@ impl Dynamic {
|
||||
/// This method is deprecated. Use [`into_immutable_string`][Dynamic::into_immutable_string] instead.
|
||||
///
|
||||
/// This method will be removed in the next major version.
|
||||
#[deprecated(since = "1.0.1", note = "use `into_immutable_string` instead")]
|
||||
#[deprecated(since = "1.1.0", note = "use `into_immutable_string` instead")]
|
||||
#[inline(always)]
|
||||
pub fn as_immutable_string(self) -> Result<ImmutableString, &'static str> {
|
||||
self.into_immutable_string()
|
||||
|
@ -1745,16 +1745,39 @@ impl Engine {
|
||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||
///
|
||||
/// Not available under `no_std` or `WASM`.
|
||||
///
|
||||
/// # Deprecated
|
||||
///
|
||||
/// This method is deprecated. Use [`run_file`][Engine::run_file] instead.
|
||||
///
|
||||
/// This method will be removed in the next major version.
|
||||
#[deprecated(since = "1.1.0", note = "use `run_file` instead")]
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||
#[inline(always)]
|
||||
pub fn consume_file(&self, path: std::path::PathBuf) -> Result<(), Box<EvalAltResult>> {
|
||||
Self::read_file(path).and_then(|contents| self.consume(&contents))
|
||||
self.run_file(path)
|
||||
}
|
||||
/// Evaluate a file, returning any error (if any).
|
||||
///
|
||||
/// Not available under `no_std` or `WASM`.
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||
#[inline(always)]
|
||||
pub fn run_file(&self, path: std::path::PathBuf) -> Result<(), Box<EvalAltResult>> {
|
||||
Self::read_file(path).and_then(|contents| self.run(&contents))
|
||||
}
|
||||
/// Evaluate a file with own scope, but throw away the result and only return error (if any).
|
||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||
///
|
||||
/// Not available under `no_std` or `WASM`.
|
||||
///
|
||||
/// # Deprecated
|
||||
///
|
||||
/// This method is deprecated. Use [`run_file_with_scope`][Engine::run_file_with_scope] instead.
|
||||
///
|
||||
/// This method will be removed in the next major version.
|
||||
#[deprecated(since = "1.1.0", note = "use `run_file_with_scope` instead")]
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||
#[inline(always)]
|
||||
@ -1763,21 +1786,62 @@ impl Engine {
|
||||
scope: &mut Scope,
|
||||
path: std::path::PathBuf,
|
||||
) -> Result<(), Box<EvalAltResult>> {
|
||||
Self::read_file(path).and_then(|contents| self.consume_with_scope(scope, &contents))
|
||||
self.run_file_with_scope(scope, path)
|
||||
}
|
||||
/// Evaluate a file with own scope, returning any error (if any).
|
||||
///
|
||||
/// Not available under `no_std` or `WASM`.
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||
#[inline(always)]
|
||||
pub fn run_file_with_scope(
|
||||
&self,
|
||||
scope: &mut Scope,
|
||||
path: std::path::PathBuf,
|
||||
) -> Result<(), Box<EvalAltResult>> {
|
||||
Self::read_file(path).and_then(|contents| self.run_with_scope(scope, &contents))
|
||||
}
|
||||
/// Evaluate a string, but throw away the result and only return error (if any).
|
||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||
///
|
||||
/// # Deprecated
|
||||
///
|
||||
/// This method is deprecated. Use [`run`][Engine::run] instead.
|
||||
///
|
||||
/// This method will be removed in the next major version.
|
||||
#[deprecated(since = "1.1.0", note = "use `run` instead")]
|
||||
#[inline(always)]
|
||||
pub fn consume(&self, script: &str) -> Result<(), Box<EvalAltResult>> {
|
||||
self.consume_with_scope(&mut Default::default(), script)
|
||||
self.run(script)
|
||||
}
|
||||
/// Evaluate a script, returning any error (if any).
|
||||
#[inline(always)]
|
||||
pub fn run(&self, script: &str) -> Result<(), Box<EvalAltResult>> {
|
||||
self.run_with_scope(&mut Default::default(), script)
|
||||
}
|
||||
/// Evaluate a string with own scope, but throw away the result and only return error (if any).
|
||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||
#[inline]
|
||||
///
|
||||
/// # Deprecated
|
||||
///
|
||||
/// This method is deprecated. Use [`run_with_scope`][Engine::run_with_scope] instead.
|
||||
///
|
||||
/// This method will be removed in the next major version.
|
||||
#[deprecated(since = "1.1.0", note = "use `run_with_scope` instead")]
|
||||
#[inline(always)]
|
||||
pub fn consume_with_scope(
|
||||
&self,
|
||||
scope: &mut Scope,
|
||||
script: &str,
|
||||
) -> Result<(), Box<EvalAltResult>> {
|
||||
self.run_with_scope(scope, script)
|
||||
}
|
||||
/// Evaluate a script with own scope, returning any error (if any).
|
||||
#[inline]
|
||||
pub fn run_with_scope(
|
||||
&self,
|
||||
scope: &mut Scope,
|
||||
script: &str,
|
||||
) -> Result<(), Box<EvalAltResult>> {
|
||||
let scripts = [script];
|
||||
let (stream, tokenizer_control) = self.lex_raw(&scripts, None);
|
||||
@ -1790,21 +1854,49 @@ impl Engine {
|
||||
self.optimization_level,
|
||||
)?;
|
||||
|
||||
self.consume_ast_with_scope(scope, &ast)
|
||||
self.run_ast_with_scope(scope, &ast)
|
||||
}
|
||||
/// Evaluate an AST, but throw away the result and only return error (if any).
|
||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||
///
|
||||
/// # Deprecated
|
||||
///
|
||||
/// This method is deprecated. Use [`run_ast`][Engine::run_ast] instead.
|
||||
///
|
||||
/// This method will be removed in the next major version.
|
||||
#[deprecated(since = "1.1.0", note = "use `run_ast` instead")]
|
||||
#[inline(always)]
|
||||
pub fn consume_ast(&self, ast: &AST) -> Result<(), Box<EvalAltResult>> {
|
||||
self.consume_ast_with_scope(&mut Default::default(), ast)
|
||||
self.run_ast(ast)
|
||||
}
|
||||
/// Evaluate an AST, returning any error (if any).
|
||||
#[inline(always)]
|
||||
pub fn run_ast(&self, ast: &AST) -> Result<(), Box<EvalAltResult>> {
|
||||
self.run_ast_with_scope(&mut Default::default(), ast)
|
||||
}
|
||||
/// Evaluate an [`AST`] with own scope, but throw away the result and only return error (if any).
|
||||
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
||||
#[inline]
|
||||
///
|
||||
/// # Deprecated
|
||||
///
|
||||
/// This method is deprecated. Use [`run_ast_with_scope`][Engine::run_ast_with_scope] instead.
|
||||
///
|
||||
/// This method will be removed in the next major version.
|
||||
#[deprecated(since = "1.1.0", note = "use `run_ast_with_scope` instead")]
|
||||
#[inline(always)]
|
||||
pub fn consume_ast_with_scope(
|
||||
&self,
|
||||
scope: &mut Scope,
|
||||
ast: &AST,
|
||||
) -> Result<(), Box<EvalAltResult>> {
|
||||
self.run_ast_with_scope(scope, ast)
|
||||
}
|
||||
/// Evaluate an [`AST`] with own scope, returning any error (if any).
|
||||
#[inline]
|
||||
pub fn run_ast_with_scope(
|
||||
&self,
|
||||
scope: &mut Scope,
|
||||
ast: &AST,
|
||||
) -> Result<(), Box<EvalAltResult>> {
|
||||
let mods = &mut Default::default();
|
||||
let mut state = EvalState::new();
|
||||
@ -2151,7 +2243,7 @@ impl Engine {
|
||||
/// }
|
||||
/// });
|
||||
///
|
||||
/// engine.consume("for x in range(0, 50000) {}")
|
||||
/// engine.run("for x in range(0, 50000) {}")
|
||||
/// .expect_err("should error");
|
||||
///
|
||||
/// assert_eq!(*result.read().unwrap(), 9600);
|
||||
@ -2186,7 +2278,7 @@ impl Engine {
|
||||
/// let logger = result.clone();
|
||||
/// engine.on_print(move |s| logger.write().unwrap().push_str(s));
|
||||
///
|
||||
/// engine.consume("print(40 + 2);")?;
|
||||
/// engine.run("print(40 + 2);")?;
|
||||
///
|
||||
/// assert_eq!(*result.read().unwrap(), "42");
|
||||
/// # Ok(())
|
||||
@ -2219,7 +2311,7 @@ impl Engine {
|
||||
///
|
||||
/// let mut ast = engine.compile(r#"let x = "hello"; debug(x);"#)?;
|
||||
/// ast.set_source("world");
|
||||
/// engine.consume_ast(&ast)?;
|
||||
/// engine.run_ast(&ast)?;
|
||||
///
|
||||
/// #[cfg(not(feature = "no_position"))]
|
||||
/// assert_eq!(*result.read().unwrap(), r#"world @ 1:18 > "hello""#);
|
||||
|
@ -15,7 +15,7 @@ fn test_constant() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
assert!(matches!(
|
||||
*engine.consume("const x = [1, 2, 3, 4, 5]; x[2] = 42;").expect_err("expects error"),
|
||||
*engine.run("const x = [1, 2, 3, 4, 5]; x[2] = 42;").expect_err("expects error"),
|
||||
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "x"
|
||||
));
|
||||
|
||||
@ -30,7 +30,7 @@ fn test_constant_scope() -> Result<(), Box<EvalAltResult>> {
|
||||
scope.push_constant("x", 42 as INT);
|
||||
|
||||
assert!(matches!(
|
||||
*engine.consume_with_scope(&mut scope, "x = 1").expect_err("expects error"),
|
||||
*engine.run_with_scope(&mut scope, "x = 1").expect_err("expects error"),
|
||||
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "x"
|
||||
));
|
||||
|
||||
@ -80,7 +80,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
assert!(matches!(
|
||||
*engine
|
||||
.consume(
|
||||
.run(
|
||||
"
|
||||
const MY_NUMBER = new_ts();
|
||||
MY_NUMBER.value = 42;
|
||||
@ -118,7 +118,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
assert!(matches!(
|
||||
*engine
|
||||
.consume_with_scope(&mut scope, "MY_NUMBER.value = 42;")
|
||||
.run_with_scope(&mut scope, "MY_NUMBER.value = 42;")
|
||||
.expect_err("should error"),
|
||||
EvalAltResult::ErrorAssignmentToConstant(_, _)
|
||||
));
|
||||
|
@ -6,7 +6,7 @@ use rhai::{
|
||||
fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
engine.consume("while false {}")?;
|
||||
engine.run("while false {}")?;
|
||||
|
||||
// Disable 'while' and make sure it still works with custom syntax
|
||||
engine.disable_symbol("while");
|
||||
@ -79,7 +79,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
assert!(matches!(
|
||||
*engine
|
||||
.consume("let foo = (exec [x<<15] -> { x += 2 } while x < 42) * 10;")
|
||||
.run("let foo = (exec [x<<15] -> { x += 2 } while x < 42) * 10;")
|
||||
.expect_err("should error"),
|
||||
EvalAltResult::ErrorRuntime(_, _)
|
||||
));
|
||||
|
@ -208,7 +208,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
assert!(matches!(
|
||||
*engine
|
||||
.consume(
|
||||
.run(
|
||||
"
|
||||
let x = #{};
|
||||
loop { x.a = x; }
|
||||
|
@ -368,7 +368,7 @@ fn test_module_from_ast() -> Result<(), Box<EvalAltResult>> {
|
||||
);
|
||||
assert!(matches!(
|
||||
*engine
|
||||
.consume(r#"import "testing" as ttt; ttt::hidden()"#)
|
||||
.run(r#"import "testing" as ttt; ttt::hidden()"#)
|
||||
.expect_err("should error"),
|
||||
EvalAltResult::ErrorFunctionNotFound(fn_name, _) if fn_name == "ttt::hidden ()"
|
||||
));
|
||||
@ -498,7 +498,7 @@ fn test_module_ast_namespace2() -> Result<(), Box<EvalAltResult>> {
|
||||
static_modules.insert("test_module", module);
|
||||
engine.set_module_resolver(static_modules);
|
||||
|
||||
engine.consume(SCRIPT)?;
|
||||
engine.run(SCRIPT)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -87,11 +87,11 @@ fn test_plugins_package() -> Result<(), Box<EvalAltResult>> {
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
{
|
||||
assert_eq!(engine.eval::<INT>("let a = [1, 2, 3]; a.foo")?, 1);
|
||||
engine.consume("const A = [1, 2, 3]; A.no_effect(42);")?;
|
||||
engine.consume("const A = [1, 2, 3]; A.no_effect = 42;")?;
|
||||
engine.run("const A = [1, 2, 3]; A.no_effect(42);")?;
|
||||
engine.run("const A = [1, 2, 3]; A.no_effect = 42;")?;
|
||||
|
||||
assert!(
|
||||
matches!(*engine.consume("const A = [1, 2, 3]; A.test(42);").expect_err("should error"),
|
||||
matches!(*engine.run("const A = [1, 2, 3]; A.test(42);").expect_err("should error"),
|
||||
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "array")
|
||||
)
|
||||
}
|
||||
|
@ -50,10 +50,10 @@ fn test_print_debug() -> Result<(), Box<EvalAltResult>> {
|
||||
});
|
||||
|
||||
// Evaluate script
|
||||
engine.consume("print(40 + 2)")?;
|
||||
engine.run("print(40 + 2)")?;
|
||||
let mut ast = engine.compile(r#"let x = "hello!"; debug(x)"#)?;
|
||||
ast.set_source("world");
|
||||
engine.consume_ast(&ast)?;
|
||||
engine.run_ast(&ast)?;
|
||||
|
||||
// 'logbook' captures all the 'print' and 'debug' output
|
||||
assert_eq!(logbook.read().unwrap().len(), 2);
|
||||
@ -96,7 +96,7 @@ fn test_print_custom_type() -> Result<(), Box<EvalAltResult>> {
|
||||
.register_fn("debug", |x: &mut MyStruct| x.to_string())
|
||||
.register_fn("new_ts", || MyStruct { field: 42 });
|
||||
|
||||
engine.consume("let x = new_ts(); debug(x);")?;
|
||||
engine.run("let x = new_ts(); debug(x);")?;
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
assert_eq!(
|
||||
|
@ -74,7 +74,7 @@ fn test_side_effects_print() -> Result<(), Box<EvalAltResult>> {
|
||||
let logger = result.clone();
|
||||
engine.on_print(move |s| logger.write().unwrap().push_str(s));
|
||||
|
||||
engine.consume("print(40 + 2);")?;
|
||||
engine.run("print(40 + 2);")?;
|
||||
|
||||
assert_eq!(*result.read().unwrap(), "42");
|
||||
Ok(())
|
||||
|
@ -57,9 +57,9 @@ fn test_infinite_loops() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
engine.set_max_operations(1024);
|
||||
|
||||
assert!(engine.consume("loop {}").is_err());
|
||||
assert!(engine.consume("while true {}").is_err());
|
||||
assert!(engine.consume("do {} while true").is_err());
|
||||
assert!(engine.run("loop {}").is_err());
|
||||
assert!(engine.run("while true {}").is_err());
|
||||
assert!(engine.run("do {} while true").is_err());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user