From 362b5709ff63827d616c285a2f077aaabb5a9fd1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 17 Sep 2024 17:16:57 -0700 Subject: [PATCH] change api again --- src/runner/mod.rs | 2 +- src/runner/runner.rs | 26 ++++++++++++++++++++------ src/script.rs | 6 ++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/runner/mod.rs b/src/runner/mod.rs index e525f41..9b6e5d2 100644 --- a/src/runner/mod.rs +++ b/src/runner/mod.rs @@ -1,3 +1,3 @@ mod runner; -pub use runner::{run,Error}; +pub use runner::Runner; diff --git a/src/runner/runner.rs b/src/runner/runner.rs index f670fbf..c03c38e 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -1,10 +1,24 @@ -pub enum Error{ - Lua(mlua::Error), +pub struct Runner{ + lua:mlua::Lua, } -pub fn run(source:String,context:&mut crate::context::Context)->Result<(),Error>{ - let lua=mlua::Lua::new(); - lua.sandbox(true).map_err(Error::Lua)?; - lua.load(source).exec().map_err(Error::Lua)?; +fn init(lua:&mlua::Lua)->mlua::Result<()>{ Ok(()) } + +impl Runner{ + pub fn new()->mlua::Result{ + let runner=Self{ + lua:mlua::Lua::new(), + }; + init(&runner.lua)?; + Ok(runner) + } + pub fn set_script(&self,script:rbx_dom_weak::types::Ref)->mlua::Result<()>{ + Ok(()) + } + pub fn run(&self,source:String,context:&mut crate::context::Context)->mlua::Result<()>{ + //Set up dom access here? + self.lua.load(source).exec() + } +} diff --git a/src/script.rs b/src/script.rs index b893afd..a17b7ab 100644 --- a/src/script.rs +++ b/src/script.rs @@ -1,7 +1,7 @@ use rbx_dom_weak::types::Ref; pub enum Error{ - Runner(crate::runner::Error), + Runner(mlua::Error), NoScript, NoSource, } @@ -23,6 +23,8 @@ impl Script{ } }; // run it lole - crate::runner::run(source,context).map_err(Error::Runner) + let runner=crate::runner::Runner::new().map_err(Error::Runner)?; + runner.set_script(self.script).map_err(Error::Runner)?; + runner.run(source,context).map_err(Error::Runner) } }