Add string concat/compare. Bump to 0.4
This commit is contained in:
parent
7a46c7d9bc
commit
2a28209b38
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rhai"
|
name = "rhai"
|
||||||
version = "0.3.1"
|
version = "0.4.0"
|
||||||
authors = ["Jonathan Turner"]
|
authors = ["Jonathan Turner"]
|
||||||
description = "Embedded scripting for Rust"
|
description = "Embedded scripting for Rust"
|
||||||
homepage = "https://github.com/jonathandturner/rhai"
|
homepage = "https://github.com/jonathandturner/rhai"
|
||||||
|
@ -12,7 +12,7 @@ Rhai's current feature set:
|
|||||||
* No additional dependencies
|
* No additional dependencies
|
||||||
* No unsafe code
|
* 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
|
## Installation
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ You can install Rhai using crates by adding this line to your dependences:
|
|||||||
|
|
||||||
```
|
```
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rhai = "0.3.0"
|
rhai = "0.4.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
|
@ -2,3 +2,6 @@ print("hello");
|
|||||||
print("this\nis \\ nice");
|
print("this\nis \\ nice");
|
||||||
print("40 hex is \x40");
|
print("40 hex is \x40");
|
||||||
print("fun with unicode: \u2764 and \U0001F603");
|
print("fun with unicode: \u2764 and \U0001F603");
|
||||||
|
print("foo" + " " + "bar");
|
||||||
|
print("foo" < "bar");
|
||||||
|
print("foo" >= "bar");
|
@ -1314,22 +1314,27 @@ impl Engine {
|
|||||||
fn or(x: bool, y: bool) -> bool {
|
fn or(x: bool, y: bool) -> bool {
|
||||||
x || y
|
x || y
|
||||||
}
|
}
|
||||||
|
fn concat(x: String, y: String) -> String {
|
||||||
|
x + &y
|
||||||
|
}
|
||||||
|
|
||||||
reg_op!(engine, "+", add, i32, i64, u32, u64, f32, f64);
|
reg_op!(engine, "+", add, i32, i64, u32, u64, f32, f64);
|
||||||
reg_op!(engine, "-", sub, 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, "*", mul, i32, i64, u32, u64, f32, f64);
|
||||||
reg_op!(engine, "/", div, 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, "<", lt, i32, i64, u32, u64, String);
|
||||||
reg_cmp!(engine, "<=", lte, i32, i64, u32, u64);
|
reg_cmp!(engine, "<=", lte, i32, i64, u32, u64, String);
|
||||||
reg_cmp!(engine, ">", gt, i32, i64, u32, u64);
|
reg_cmp!(engine, ">", gt, i32, i64, u32, u64, String);
|
||||||
reg_cmp!(engine, ">=", gte, i32, i64, u32, u64);
|
reg_cmp!(engine, ">=", gte, i32, i64, u32, u64, String);
|
||||||
reg_cmp!(engine, "==", eq, i32, i64, u32, u64, bool);
|
reg_cmp!(engine, "==", eq, i32, i64, u32, u64, bool, String);
|
||||||
reg_cmp!(engine, "!=", ne, i32, i64, u32, u64, bool);
|
reg_cmp!(engine, "!=", ne, i32, i64, u32, u64, bool, String);
|
||||||
|
|
||||||
reg_op!(engine, "||", or, bool);
|
reg_op!(engine, "||", or, bool);
|
||||||
reg_op!(engine, "&&", and, bool);
|
reg_op!(engine, "&&", and, bool);
|
||||||
|
|
||||||
|
engine.register_fn("+", concat);
|
||||||
|
|
||||||
// engine.register_fn("[]", idx);
|
// engine.register_fn("[]", idx);
|
||||||
// FIXME? Registering array lookups are a special case because we want to return boxes
|
// 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());
|
// directly let ent = engine.fns.entry("[]".to_string()).or_insert(Vec::new());
|
||||||
@ -1676,6 +1681,12 @@ fn test_string() {
|
|||||||
} else {
|
} else {
|
||||||
assert!(false);
|
assert!(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Ok(result) = engine.eval::<String>("\"foo\" + \"bar\"") {
|
||||||
|
assert_eq!(result, "foobar");
|
||||||
|
} else {
|
||||||
|
assert!(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use std::io::prelude::*;
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
|
Loading…
Reference in New Issue
Block a user