Compare commits
6 Commits
5f1b93aa28
...
2c4b58c5ca
Author | SHA1 | Date | |
---|---|---|---|
2c4b58c5ca | |||
909c00c5f6 | |||
3981d25305 | |||
442d7af333 | |||
4823d73a85 | |||
de7a2c22be |
@ -109,7 +109,7 @@ impl Runner{
|
||||
self.lua.set_app_data::<crate::scheduler::Scheduler>(crate::scheduler::Scheduler::default());
|
||||
Ok(Runnable{
|
||||
lua:self.lua,
|
||||
_lifetime:&std::marker::PhantomData
|
||||
_lifetime:&std::marker::PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -117,7 +117,7 @@ impl Runner{
|
||||
//Runnable is the same thing but has context set, which it holds the lifetime for.
|
||||
pub struct Runnable<'a>{
|
||||
lua:mlua::Lua,
|
||||
_lifetime:&'a std::marker::PhantomData<()>
|
||||
_lifetime:&'a std::marker::PhantomData<()>,
|
||||
}
|
||||
impl Runnable<'_>{
|
||||
pub fn drop_context(self)->Runner{
|
||||
@ -129,10 +129,19 @@ impl Runnable<'_>{
|
||||
}
|
||||
pub fn run_script(&self,script:super::instance::Instance)->Result<(),Error>{
|
||||
let (name,source)=super::instance::get_name_source(&self.lua,script).map_err(Error::RustLua)?;
|
||||
self.lua.globals().raw_set("script",script).map_err(Error::RustLua)?;
|
||||
let f=self.lua.load(source.as_str())
|
||||
.set_name(name).into_function().map_err(Error::RustLua)?;
|
||||
// TODO: set_environment without losing the ability to print from Lua
|
||||
|
||||
// let fenv=self.lua.create_table().map_err(Error::RustLua)?;
|
||||
// //there's gotta be a more concise way to do this
|
||||
// for pair in f.environment().unwrap().pairs::<mlua::Value,mlua::Value>(){
|
||||
// let (k,v)=pair.map_err(Error::RustLua)?;
|
||||
// fenv.raw_set(k,v).map_err(Error::RustLua)?;
|
||||
// }
|
||||
// fenv.raw_set("script",script).map_err(Error::RustLua)?;
|
||||
// f.set_environment(fenv).map_err(Error::RustLua)?;
|
||||
self.lua.globals().raw_set("script",script).map_err(Error::RustLua)?;
|
||||
|
||||
let thread=self.lua.create_thread(f).map_err(Error::RustLua)?;
|
||||
thread.resume::<mlua::MultiValue>(()).map_err(|error|Error::Lua{source,error})?;
|
||||
// wait() is called from inside Lua and goes to a rust function that schedules the thread and then yields
|
||||
|
Loading…
Reference in New Issue
Block a user