more api
This commit is contained in:
parent
c0323d12df
commit
e110365325
@ -12,6 +12,7 @@ pub enum Error{
|
|||||||
RustLua(mlua::Error),
|
RustLua(mlua::Error),
|
||||||
Script(super::instance::GetScriptError),
|
Script(super::instance::GetScriptError),
|
||||||
NoContext,
|
NoContext,
|
||||||
|
NoServices,
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for Error{
|
impl std::fmt::Display for Error{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
@ -46,7 +47,11 @@ impl Runner{
|
|||||||
init(&runner.lua).map_err(Error::RustLua)?;
|
init(&runner.lua).map_err(Error::RustLua)?;
|
||||||
Ok(runner)
|
Ok(runner)
|
||||||
}
|
}
|
||||||
pub fn runnable_context<'a>(self,context:&'a mut Context,services:&crate::place::Services)->Result<Runnable<'a>,Error>{
|
pub fn runnable_context<'a>(self,context:&'a mut Context)->Result<Runnable<'a>,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<Runnable<'a>,Error>{
|
||||||
{
|
{
|
||||||
let globals=self.lua.globals();
|
let globals=self.lua.globals();
|
||||||
globals.set("game",super::instance::DataModel::new(services.game)).map_err(Error::RustLua)?;
|
globals.set("game",super::instance::DataModel::new(services.game)).map_err(Error::RustLua)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user