change api again
This commit is contained in:
parent
2ccc5bb17d
commit
362b5709ff
@ -1,3 +1,3 @@
|
|||||||
mod runner;
|
mod runner;
|
||||||
|
|
||||||
pub use runner::{run,Error};
|
pub use runner::Runner;
|
||||||
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user