Add support for character constants
This commit is contained in:
28
examples/arrays_and_structs.rs
Normal file
28
examples/arrays_and_structs.rs
Normal 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]"));
|
||||
}
|
@@ -3,7 +3,7 @@ use rhai::{Engine, FnRegister};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct TestStruct {
|
||||
x: i32
|
||||
x: i64
|
||||
}
|
||||
|
||||
impl TestStruct {
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user