Add support for character constants

This commit is contained in:
jonathandturner
2016-04-13 18:40:06 -07:00
parent 3364191781
commit b9ea072d6a
7 changed files with 180 additions and 17 deletions

View File

@@ -0,0 +1,28 @@
extern crate rhai;
use rhai::{Engine, FnRegister};
#[derive(Clone, Debug)]
struct TestStruct {
x: i64
}
impl TestStruct {
fn update(&mut self) {
self.x += 1000;
}
fn new() -> TestStruct {
TestStruct { x: 1 }
}
}
fn main() {
let mut engine = Engine::new();
engine.register_type::<TestStruct>();
engine.register_fn("update", TestStruct::update);
engine.register_fn("new_ts", TestStruct::new);
println!("{:?}", engine.eval::<TestStruct>("var x = [new_ts()]; x[0].update(); x[0]"));
}

View File

@@ -3,7 +3,7 @@ use rhai::{Engine, FnRegister};
#[derive(Clone)]
struct TestStruct {
x: i32
x: i64
}
impl TestStruct {

View File

@@ -4,7 +4,7 @@ use rhai::Engine;
fn main() {
let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i32>("40 + 2") {
if let Ok(result) = engine.eval::<i64>("40 + 2") {
println!("Answer: {}", result); // prints 42
}
}

View File

@@ -5,9 +5,9 @@ fn main() {
let mut engine = Engine::new();
let mut scope: Scope = Vec::new();
if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "var x = 4 + 5") { } else { assert!(false); }
if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "var x = 4 + 5") { } else { assert!(false); }
if let Ok(result) = engine.eval_with_scope::<i32>(&mut scope, "x") {
if let Ok(result) = engine.eval_with_scope::<i64>(&mut scope, "x") {
println!("result: {}", result);
}
}

View File

@@ -1,7 +1,7 @@
extern crate rhai;
use rhai::{Engine, FnRegister};
fn add(x: i32, y: i32) -> i32 {
fn add(x: i64, y: i64) -> i64 {
x + y
}
@@ -10,7 +10,7 @@ fn main() {
engine.register_fn("add", add);
if let Ok(result) = engine.eval::<i32>("add(40, 2)") {
if let Ok(result) = engine.eval::<i64>("add(40, 2)") {
println!("Answer: {}", result); // prints 42
}
}