diff --git a/Cargo.toml b/Cargo.toml index cb99d7d4..3ca3ac91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhai" -version = "0.3.1" +version = "0.4.0" authors = ["Jonathan Turner"] description = "Embedded scripting for Rust" homepage = "https://github.com/jonathandturner/rhai" diff --git a/README.md b/README.md index 797ea241..367968a8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Rhai's current feature set: * No additional dependencies * No unsafe code -**Note:** Currently, it's version 0.3.0, so the language and APIs may change before they stabilize.* +**Note:** Currently, it's version 0.4.0, so the language and APIs may change before they stabilize.* ## Installation @@ -20,7 +20,7 @@ You can install Rhai using crates by adding this line to your dependences: ``` [dependencies] -rhai = "0.3.0" +rhai = "0.4.0" ``` ## Related diff --git a/scripts/string.rhai b/scripts/string.rhai index bdd22023..ecf418ec 100644 --- a/scripts/string.rhai +++ b/scripts/string.rhai @@ -2,3 +2,6 @@ print("hello"); print("this\nis \\ nice"); print("40 hex is \x40"); print("fun with unicode: \u2764 and \U0001F603"); +print("foo" + " " + "bar"); +print("foo" < "bar"); +print("foo" >= "bar"); \ No newline at end of file diff --git a/src/engine.rs b/src/engine.rs index 4283ff80..96b0e62c 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1314,22 +1314,27 @@ impl Engine { fn or(x: bool, y: bool) -> bool { x || y } + fn concat(x: String, y: String) -> String { + x + &y + } reg_op!(engine, "+", add, i32, i64, u32, u64, f32, f64); reg_op!(engine, "-", sub, i32, i64, u32, u64, f32, f64); reg_op!(engine, "*", mul, i32, i64, u32, u64, f32, f64); reg_op!(engine, "/", div, i32, i64, u32, u64, f32, f64); - reg_cmp!(engine, "<", lt, i32, i64, u32, u64); - reg_cmp!(engine, "<=", lte, i32, i64, u32, u64); - reg_cmp!(engine, ">", gt, i32, i64, u32, u64); - reg_cmp!(engine, ">=", gte, i32, i64, u32, u64); - reg_cmp!(engine, "==", eq, i32, i64, u32, u64, bool); - reg_cmp!(engine, "!=", ne, i32, i64, u32, u64, bool); + reg_cmp!(engine, "<", lt, i32, i64, u32, u64, String); + reg_cmp!(engine, "<=", lte, i32, i64, u32, u64, String); + reg_cmp!(engine, ">", gt, i32, i64, u32, u64, String); + reg_cmp!(engine, ">=", gte, i32, i64, u32, u64, String); + reg_cmp!(engine, "==", eq, i32, i64, u32, u64, bool, String); + reg_cmp!(engine, "!=", ne, i32, i64, u32, u64, bool, String); reg_op!(engine, "||", or, bool); reg_op!(engine, "&&", and, bool); + engine.register_fn("+", concat); + // engine.register_fn("[]", idx); // FIXME? Registering array lookups are a special case because we want to return boxes // directly let ent = engine.fns.entry("[]".to_string()).or_insert(Vec::new()); @@ -1676,6 +1681,12 @@ fn test_string() { } else { assert!(false); } + + if let Ok(result) = engine.eval::("\"foo\" + \"bar\"") { + assert_eq!(result, "foobar"); + } else { + assert!(false); + } } #[test] diff --git a/src/parser.rs b/src/parser.rs index 9a559db5..822d1fd7 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,4 +1,3 @@ -use std::io::prelude::*; use std::error::Error; use std::fmt; use std::iter::Peekable;