2020-03-24 02:49:08 +01:00
|
|
|
use rhai::{Engine, RegisterFn, INT};
|
2016-04-14 03:40:06 +02:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
struct TestStruct {
|
2020-03-24 02:49:08 +01:00
|
|
|
x: INT,
|
2016-04-14 03:40:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TestStruct {
|
|
|
|
fn update(&mut self) {
|
|
|
|
self.x += 1000;
|
|
|
|
}
|
|
|
|
|
2020-03-19 06:52:10 +01:00
|
|
|
fn new() -> Self {
|
2016-04-14 03:40:06 +02:00
|
|
|
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);
|
|
|
|
|
2019-09-18 12:21:07 +02:00
|
|
|
println!(
|
|
|
|
"{:?}",
|
|
|
|
engine.eval::<TestStruct>("let x = new_ts(); x.update(); x")
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"{:?}",
|
|
|
|
engine.eval::<TestStruct>("let x = [new_ts()]; x[0].update(); x[0]")
|
|
|
|
);
|
2016-04-14 03:40:06 +02:00
|
|
|
}
|