2024-09-16 18:54:04 -07:00
|
|
|
use rbx_dom_weak::types::Ref;
|
|
|
|
|
|
|
|
pub enum Error{
|
2024-09-17 17:16:57 -07:00
|
|
|
Runner(mlua::Error),
|
2024-09-16 18:54:04 -07:00
|
|
|
NoScript,
|
|
|
|
NoSource,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Script{
|
|
|
|
script:Ref,
|
|
|
|
}
|
|
|
|
impl Script{
|
|
|
|
pub const fn new(script:Ref)->Self{
|
|
|
|
Self{script}
|
|
|
|
}
|
|
|
|
pub fn run(&self,context:&mut crate::context::Context)->Result<(),Error>{
|
|
|
|
// grab source
|
|
|
|
let source={
|
|
|
|
let instance=context.dom.get_by_ref(self.script).ok_or(Error::NoScript)?;
|
|
|
|
match instance.properties.get("Source").ok_or(Error::NoSource)?{
|
|
|
|
rbx_dom_weak::types::Variant::String(s)=>s.clone(),
|
|
|
|
_=>Err(Error::NoSource)?,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// run it lole
|
2024-09-17 17:16:57 -07:00
|
|
|
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)
|
2024-09-16 18:54:04 -07:00
|
|
|
}
|
|
|
|
}
|