diff --git a/src/runner/runner.rs b/src/runner/runner.rs index d10c4ab..74910ed 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -12,17 +12,15 @@ pub enum Error{ source:String, error:mlua::Error }, + RustLua(mlua::Error), Script(super::instance::GetScriptError), - /// If the lua.remove_app_data function fails - RemoveAppData, } -impl Error{ - pub fn print(self){ +impl std::fmt::Display for Error{ + fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ match self{ - Self::Lua{source,error:mlua::Error::RuntimeError(s)}=>{ - println!("lua error: {s}\nsource:{source}"); - }, - other=>println!("{:?}",other), + Self::Lua{source,error:mlua::Error::RuntimeError(s)}=>write!(f,"lua error: {s}\nsource:{source}"), + Self::RustLua(mlua::Error::RuntimeError(s))=>write!(f,"rust-side lua error: {s}"), + other=>write!(f,"{other:?}"), } } } @@ -72,16 +70,16 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{ } impl Runner{ - pub fn new()->mlua::Result{ + pub fn new()->Result{ let runner=Self{ lua:mlua::Lua::new(), }; - init(&runner.lua)?; + init(&runner.lua).map_err(Error::RustLua)?; Ok(runner) } pub fn run_script(&self,script:super::instance::Script,context:&mut Context)->Result<(),Error>{ let (name,source)=script.get_name_source(context).map_err(Error::Script)?; - self.lua.globals().set("script",script).map_err(|error|Error::Lua{source:source.clone(),error})?; + self.lua.globals().set("script",script).map_err(Error::RustLua)?; //this makes set_app_data shut up about the lifetime self.lua.set_app_data::<&'static mut rbx_dom_weak::WeakDom>(unsafe{core::mem::transmute(&mut context.dom)}); let r=self.lua.load(source.as_str())