From bda399a5b410cf90b47c3285c904c6acb9ceac99 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 28 Apr 2020 13:30:24 +0100 Subject: [PATCH] Get yield function in the moment of async callback creation. This is usefull to temporary override `coroutine.yield` prior to create_async_callback() and then restore to original value. --- src/lua.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index 90b54de..12feca9 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -1234,9 +1234,11 @@ impl Lua { Function(self.pop_ref()) }; + let coroutine = self.globals().get::<_, Table>("coroutine")?; + let env = self.create_table()?; env.set("get_poll", get_poll)?; - env.set("coroutine", self.globals().get::<_, Value>("coroutine")?)?; + env.set("yield", coroutine.get::<_, Function>("yield")?)?; env.set( "unpack", self.create_function(|_, tbl: Table| { @@ -1254,7 +1256,7 @@ impl Lua { if ready then return unpack(res) end - coroutine.yield(res) + yield(res) end "#, )