From fc50632a6f999e554999003153ece71e3d568c80 Mon Sep 17 00:00:00 2001 From: Sofia Date: Sat, 14 Mar 2026 22:23:50 +0200 Subject: [PATCH] Add print --- examples/test.lua | 2 +- src/main.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/test.lua b/examples/test.lua index 9e1d02d..ad6cd60 100644 --- a/examples/test.lua +++ b/examples/test.lua @@ -1 +1 @@ -global c = max(5, 7) \ No newline at end of file +global c = print(5, 7) \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 13d9e57..308d9ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,14 @@ impl RustFunction for Max { } } } +#[derive(Debug)] +pub struct Print; +impl RustFunction for Print { + fn execute(&self, parameters: Vec) -> Vec { + 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);