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.
This commit is contained in:
Alex Orlenko 2020-04-28 13:30:24 +01:00
parent fe5e87b0f5
commit bda399a5b4
1 changed files with 4 additions and 2 deletions

View File

@ -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
"#,
)