diff --git a/src/runner/runner.rs b/src/runner/runner.rs index 04611e6..571a978 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -85,10 +85,15 @@ 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().set("script",script).map_err(Error::RustLua)?; - self.lua.load(source.as_str()) - .set_name(name) - .exec().map_err(|error|Error::Lua{source,error}) + 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 thread=self.lua.create_thread(f).map_err(Error::RustLua)?; + thread.resume::(()).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 + // No need to schedule the thread here + Ok(()) } pub fn has_scheduled_threads(&self)->Result{ scheduler_mut(&self.lua,|scheduler|