use crate::prelude::*;
#[derive(Clone, Debug)]
pub struct TheCodeModule {
pub name: String,
pub id: Uuid,
pub codegrid_id: Uuid,
pub function: TheCodeFunction,
}
impl Default for TheCodeModule {
fn default() -> Self {
TheCodeModule::new()
}
}
impl TheCodeModule {
pub fn new() -> Self {
Self {
name: "Unnamed".to_string(),
id: Uuid::new_v4(),
codegrid_id: Uuid::nil(),
function: TheCodeFunction::default(),
}
}
pub fn set_function(&mut self, function: TheCodeFunction) {
self.function = function;
}
pub fn get_function(&self) -> &TheCodeFunction {
&self.function
}
pub fn get_function_mut(&mut self) -> &mut TheCodeFunction {
&mut self.function
}
pub fn execute(&mut self, sandbox: &mut TheCodeSandbox) -> Vec<TheValue> {
let clone = self.function.clone();
sandbox.push_current_module(self.id, self.codegrid_id);
sandbox.call_stack.push(clone);
let rc = self.function.execute(sandbox);
sandbox.call_stack.pop();
sandbox.pop_current_module();
rc
}
}