use crate::{Result, AetherError};
use rhai::{Engine, Dynamic, Scope};
use std::collections::HashMap;
pub struct AetherRuntime {
engine: Engine,
}
impl AetherRuntime {
pub fn new() -> Self {
let mut engine = Engine::new();
engine.set_max_operations(1000);
Self { engine }
}
pub fn execute(&self, script: &str, inputs: HashMap<String, Dynamic>) -> Result<Dynamic> {
let mut scope = Scope::new();
for (name, val) in inputs {
scope.push(name, val);
}
self.engine.eval_with_scope(&mut scope, script)
.map_err(|e| AetherError::ConfigError(format!("Runtime execution failed: {}", e)))
}
}
impl Default for AetherRuntime {
fn default() -> Self {
Self::new()
}
}