Add print

This commit is contained in:
Sofia 2026-03-14 22:23:50 +02:00
parent fb851093f0
commit fc50632a6f
2 changed files with 13 additions and 1 deletions

View File

@ -1 +1 @@
global c = max(5, 7)
global c = print(5, 7)

View File

@ -31,6 +31,14 @@ impl RustFunction for Max {
}
}
}
#[derive(Debug)]
pub struct Print;
impl RustFunction for Print {
fn execute(&self, parameters: Vec<vm::Value>) -> Vec<vm::Value> {
println!("{:?}", parameters);
Vec::new()
}
}
fn main() {
let file_path = PathBuf::from("../examples/test.lua");
@ -68,6 +76,10 @@ fn main() {
vm::Constant::String("max".to_owned()),
vm::Value::RustFunction(Rc::new(RefCell::new(Max))),
);
vm.environment.borrow_mut().globals.insert(
vm::Constant::String("print".to_owned()),
vm::Value::RustFunction(Rc::new(RefCell::new(Print))),
);
let closure = vm.create_closure(0);