change api again

This commit is contained in:
Quaternions 2024-09-17 17:16:57 -07:00
parent 2ccc5bb17d
commit 362b5709ff
3 changed files with 25 additions and 9 deletions

View File

@ -1,3 +1,3 @@
mod runner; mod runner;
pub use runner::{run,Error}; pub use runner::Runner;

View File

@ -1,10 +1,24 @@
pub enum Error{ pub struct Runner{
Lua(mlua::Error), lua:mlua::Lua,
} }
pub fn run(source:String,context:&mut crate::context::Context)->Result<(),Error>{ fn init(lua:&mlua::Lua)->mlua::Result<()>{
let lua=mlua::Lua::new();
lua.sandbox(true).map_err(Error::Lua)?;
lua.load(source).exec().map_err(Error::Lua)?;
Ok(()) Ok(())
} }
impl Runner{
pub fn new()->mlua::Result<Self>{
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()
}
}

View File

@ -1,7 +1,7 @@
use rbx_dom_weak::types::Ref; use rbx_dom_weak::types::Ref;
pub enum Error{ pub enum Error{
Runner(crate::runner::Error), Runner(mlua::Error),
NoScript, NoScript,
NoSource, NoSource,
} }
@ -23,6 +23,8 @@ impl Script{
} }
}; };
// run it lole // 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)
} }
} }