set_environment makes print disappear
This commit is contained in:
parent
909c00c5f6
commit
2c4b58c5ca
@ -129,16 +129,19 @@ impl Runnable<'_>{
|
|||||||
}
|
}
|
||||||
pub fn run_script(&self,script:super::instance::Instance)->Result<(),Error>{
|
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)?;
|
let (name,source)=super::instance::get_name_source(&self.lua,script).map_err(Error::RustLua)?;
|
||||||
let fenv=self.lua.create_table().map_err(Error::RustLua)?;
|
|
||||||
//there's gotta be a more concise way to do this
|
|
||||||
for pair in self.lua.globals().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)?;
|
|
||||||
let f=self.lua.load(source.as_str())
|
let f=self.lua.load(source.as_str())
|
||||||
.set_name(name).into_function().map_err(Error::RustLua)?;
|
.set_name(name).into_function().map_err(Error::RustLua)?;
|
||||||
f.set_environment(fenv).map_err(Error::RustLua)?;
|
|
||||||
|
// 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)?;
|
let thread=self.lua.create_thread(f).map_err(Error::RustLua)?;
|
||||||
thread.resume::<mlua::MultiValue>(()).map_err(|error|Error::Lua{source,error})?;
|
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
|
// 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