#![cfg(not(feature = "no_object"))] use rhai::{Engine, EvalAltResult, RegisterFn, INT}; #[test] fn test_method_call() -> Result<(), Box> { #[derive(Debug, Clone, Eq, PartialEq)] struct TestStruct { x: INT, } impl TestStruct { fn update(&mut self, n: INT) { self.x += n; } fn new() -> Self { TestStruct { x: 1 } } } let mut engine = Engine::new(); engine.register_type::(); engine.register_fn("update", TestStruct::update); engine.register_fn("new_ts", TestStruct::new); assert_eq!( engine.eval::("let x = new_ts(); x.update(1000); x")?, TestStruct { x: 1001 } ); assert_eq!( engine.eval::("let x = new_ts(); update(x, 1000); x")?, TestStruct { x: 1 } ); Ok(()) } #[test] fn test_method_call_style() -> Result<(), Box> { let mut engine = Engine::new(); assert_eq!(engine.eval::("let x = -123; x.abs(); x")?, -123); Ok(()) }