Add string concat/compare. Bump to 0.4

This commit is contained in:
Jonathan Turner 2016-08-17 18:33:31 -07:00
parent 7a46c7d9bc
commit 2a28209b38
5 changed files with 23 additions and 10 deletions

View File

@ -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"

View File

@ -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

View File

@ -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");

View File

@ -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::<String>("\"foo\" + \"bar\"") {
assert_eq!(result, "foobar");
} else {
assert!(false);
}
}
#[test]

View File

@ -1,4 +1,3 @@
use std::io::prelude::*;
use std::error::Error;
use std::fmt;
use std::iter::Peekable;