redo error stuff
This commit is contained in:
parent
0ea8551781
commit
a1626b464e
@ -12,17 +12,15 @@ pub enum Error{
|
|||||||
source:String,
|
source:String,
|
||||||
error:mlua::Error
|
error:mlua::Error
|
||||||
},
|
},
|
||||||
|
RustLua(mlua::Error),
|
||||||
Script(super::instance::GetScriptError),
|
Script(super::instance::GetScriptError),
|
||||||
/// If the lua.remove_app_data function fails
|
|
||||||
RemoveAppData,
|
|
||||||
}
|
}
|
||||||
impl Error{
|
impl std::fmt::Display for Error{
|
||||||
pub fn print(self){
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
match self{
|
match self{
|
||||||
Self::Lua{source,error:mlua::Error::RuntimeError(s)}=>{
|
Self::Lua{source,error:mlua::Error::RuntimeError(s)}=>write!(f,"lua error: {s}\nsource:{source}"),
|
||||||
println!("lua error: {s}\nsource:{source}");
|
Self::RustLua(mlua::Error::RuntimeError(s))=>write!(f,"rust-side lua error: {s}"),
|
||||||
},
|
other=>write!(f,"{other:?}"),
|
||||||
other=>println!("{:?}",other),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,16 +70,16 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Runner{
|
impl Runner{
|
||||||
pub fn new()->mlua::Result<Self>{
|
pub fn new()->Result<Self,Error>{
|
||||||
let runner=Self{
|
let runner=Self{
|
||||||
lua:mlua::Lua::new(),
|
lua:mlua::Lua::new(),
|
||||||
};
|
};
|
||||||
init(&runner.lua)?;
|
init(&runner.lua).map_err(Error::RustLua)?;
|
||||||
Ok(runner)
|
Ok(runner)
|
||||||
}
|
}
|
||||||
pub fn run_script(&self,script:super::instance::Script,context:&mut Context)->Result<(),Error>{
|
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)?;
|
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
|
//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)});
|
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())
|
let r=self.lua.load(source.as_str())
|
||||||
|
Loading…
Reference in New Issue
Block a user