redo error stuff
This commit is contained in:
parent
0ea8551781
commit
a1626b464e
@ -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<Self>{
|
||||
pub fn new()->Result<Self,Error>{
|
||||
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())
|
||||
|
Loading…
Reference in New Issue
Block a user