diff --git a/src/runner/runner.rs b/src/runner/runner.rs index bf5def1..5d7180d 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -12,6 +12,7 @@ pub enum Error{ RustLua(mlua::Error), Script(super::instance::GetScriptError), NoContext, + NoServices, } impl std::fmt::Display for Error{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ @@ -46,7 +47,11 @@ impl Runner{ init(&runner.lua).map_err(Error::RustLua)?; Ok(runner) } - pub fn runnable_context<'a>(self,context:&'a mut Context,services:&crate::place::Services)->Result,Error>{ + pub fn runnable_context<'a>(self,context:&'a mut Context)->Result,Error>{ + let services=context.find_services().ok_or(Error::NoServices)?; + self.runnable_context_with_services(context,&services) + } + pub fn runnable_context_with_services<'a>(self,context:&'a mut Context,services:&crate::context::Services)->Result,Error>{ { let globals=self.lua.globals(); globals.set("game",super::instance::DataModel::new(services.game)).map_err(Error::RustLua)?;