use rhai::{Engine, EvalAltResult, Scope}; use std::sync::Arc; use heromodels::db::hero::OurDB; // Corrected path for OurDB use heromodels::models::biz::register_biz_rhai_module; // Corrected path use std::fs; fn main() -> Result<(), Box> { println!("Executing Rhai script: examples/biz_rhai/biz.rhai"); // Create a new Rhai engine let mut engine = Engine::new(); // Create an Arc> instance // For this example, we'll use an in-memory DB. // The actual DB path or configuration might come from elsewhere in a real app. let db_instance = Arc::new(OurDB::new(".", false).expect("Failed to create DB")); // Corrected OurDB::new args and removed Mutex // Register the biz module with the engine register_biz_rhai_module(&mut engine, Arc::clone(&db_instance)); // Read the Rhai script from file let script_path = "examples/biz_rhai/biz.rhai"; let script_content = fs::read_to_string(script_path) .map_err(|e| Box::new(EvalAltResult::ErrorSystem(format!("Cannot read script file: {}", script_path), e.into())))?; // Create a new scope let mut scope = Scope::new(); // Execute the script match engine.run_with_scope(&mut scope, &script_content) { Ok(_) => { println!("Rhai script executed successfully!"); Ok(()) } Err(e) => { println!("Rhai script execution failed: {}", e); println!("Details: {:?}", e); Err(e) } } }