From f0e9d4a557074f9bda53a41079d9a41b3b083792 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 11 Jan 2022 22:12:46 +0800 Subject: [PATCH] Use run and i64 instead of eval and INT for examples. --- examples/arrays_and_structs.rs | 4 ++-- examples/custom_types_and_methods.rs | 4 ++-- examples/hello.rs | 4 ++-- examples/reuse_scope.rs | 10 +++++----- examples/simple_fn.rs | 6 +++--- examples/strings.rs | 14 +++++++------- examples/threading.rs | 8 ++++---- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/arrays_and_structs.rs b/examples/arrays_and_structs.rs index 8b29d1a8..dab0880b 100644 --- a/examples/arrays_and_structs.rs +++ b/examples/arrays_and_structs.rs @@ -1,8 +1,8 @@ -use rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult}; #[derive(Debug, Clone)] struct TestStruct { - x: INT, + x: i64, } impl TestStruct { diff --git a/examples/custom_types_and_methods.rs b/examples/custom_types_and_methods.rs index fe1777f5..b52d0a27 100644 --- a/examples/custom_types_and_methods.rs +++ b/examples/custom_types_and_methods.rs @@ -1,8 +1,8 @@ -use rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult}; #[derive(Debug, Clone)] struct TestStruct { - x: INT, + x: i64, } impl TestStruct { diff --git a/examples/hello.rs b/examples/hello.rs index 7de8898e..580315dd 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,11 +1,11 @@ -use rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult}; fn main() -> Result<(), Box> { let engine = Engine::new(); engine.run(r#"print("hello, world!")"#)?; - let result = engine.eval::("40 + 2")?; + let result = engine.eval::("40 + 2")?; println!("Answer: {}", result); // prints 42 diff --git a/examples/reuse_scope.rs b/examples/reuse_scope.rs index e7446e55..240d48c4 100644 --- a/examples/reuse_scope.rs +++ b/examples/reuse_scope.rs @@ -1,20 +1,20 @@ -use rhai::{Engine, EvalAltResult, Scope, INT}; +use rhai::{Engine, EvalAltResult, Scope}; fn main() -> Result<(), Box> { let engine = Engine::new(); let mut scope = Scope::new(); - engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?; + engine.run_with_scope(&mut scope, "let x = 4 + 5")?; - println!("x = {}", scope.get_value::("x").unwrap()); + println!("x = {}", scope.get_value::("x").unwrap()); for _ in 0..10 { - let result = engine.eval_with_scope::(&mut scope, "x += 1; x")?; + let result = engine.eval_with_scope::(&mut scope, "x += 1; x")?; println!("result: {}", result); } - println!("x = {}", scope.get_value::("x").unwrap()); + println!("x = {}", scope.get_value::("x").unwrap()); Ok(()) } diff --git a/examples/simple_fn.rs b/examples/simple_fn.rs index 9b9b000f..814e9ccf 100644 --- a/examples/simple_fn.rs +++ b/examples/simple_fn.rs @@ -1,6 +1,6 @@ -use rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult}; -fn add(x: INT, y: INT) -> INT { +fn add(x: i64, y: i64) -> i64 { x + y } @@ -9,7 +9,7 @@ fn main() -> Result<(), Box> { engine.register_fn("add", add); - let result = engine.eval::("add(40, 2)")?; + let result = engine.eval::("add(40, 2)")?; println!("Answer: {}", result); // prints 42 diff --git a/examples/strings.rs b/examples/strings.rs index 6d0489ef..a0997da2 100644 --- a/examples/strings.rs +++ b/examples/strings.rs @@ -1,6 +1,6 @@ ///! This example registers a variety of functions that operate on strings. ///! Remember to use `ImmutableString` or `&str` instead of `String` as parameters. -use rhai::{Engine, EvalAltResult, ImmutableString, Scope, INT}; +use rhai::{Engine, EvalAltResult, ImmutableString, Scope}; use std::io::{stdin, stdout, Write}; /// Trim whitespace from a string. The original string argument is changed. @@ -15,26 +15,26 @@ fn trim_string(s: &mut ImmutableString) { /// This version simply counts the number of _bytes_ in the UTF-8 representation. /// /// This version uses `&str`. -fn count_string_bytes(s: &str) -> INT { - s.len() as INT +fn count_string_bytes(s: &str) -> i64 { + s.len() as i64 } /// This version uses `ImmutableString` and `&str`. -fn find_substring(s: ImmutableString, sub: &str) -> INT { - s.find(sub).map(|x| x as INT).unwrap_or(-1) +fn find_substring(s: ImmutableString, sub: &str) -> i64 { + s.find(sub).map(|x| x as i64).unwrap_or(-1) } fn main() -> Result<(), Box> { // Create a `raw` Engine with no built-in string functions. let mut engine = Engine::new_raw(); - // Register string functions engine + // Register string functions .register_fn("trim", trim_string) .register_fn("len", count_string_bytes) .register_fn("index_of", find_substring) // Register string functions using closures - .register_fn("display", |label: &str, value: INT| { + .register_fn("display", |label: &str, value: i64| { println!("{}: {}", label, value) }) .register_fn("display", |label: ImmutableString, value: &str| { diff --git a/examples/threading.rs b/examples/threading.rs index f96a8866..d28f62d7 100644 --- a/examples/threading.rs +++ b/examples/threading.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use rhai::Engine; #[cfg(feature = "sync")] use std::sync::Mutex; @@ -23,12 +23,12 @@ fn main() { #[cfg(not(feature = "sync"))] engine .register_fn("get", move || rx_script.recv().unwrap_or_default()) - .register_fn("put", move |v: INT| tx_script.send(v).unwrap()); + .register_fn("put", move |v: i64| tx_script.send(v).unwrap()); #[cfg(feature = "sync")] engine .register_fn("get", move || rx_script.lock().unwrap().recv().unwrap()) - .register_fn("put", move |v: INT| { + .register_fn("put", move |v: i64| { tx_script.lock().unwrap().send(v).unwrap() }); @@ -54,7 +54,7 @@ fn main() { println!("Starting main loop..."); - let mut value: INT = 0; + let mut value: i64 = 0; while value < 10 { println!("Value: {}", value);