mirror of
https://github.com/lune-org/lune.git
synced 2025-01-05 19:09:10 +00:00
Use static coroutine close function instead of always fetching global
This commit is contained in:
parent
dc8206d9fd
commit
b1e7b2dd77
1 changed files with 7 additions and 3 deletions
|
@ -10,6 +10,11 @@ use smol::{channel::Sender, LocalExecutor, Timer};
|
||||||
use crate::{utils::table_builder::TableBuilder, LuneMessage};
|
use crate::{utils::table_builder::TableBuilder, LuneMessage};
|
||||||
|
|
||||||
pub fn create(lua: &Lua) -> LuaResult<()> {
|
pub fn create(lua: &Lua) -> LuaResult<()> {
|
||||||
|
// HACK: There is no way to call coroutine.close directly from the mlua
|
||||||
|
// create, so we need to fetch the function and store it in the registry
|
||||||
|
let coroutine: LuaTable = lua.globals().raw_get("coroutine")?;
|
||||||
|
let close: LuaFunction = coroutine.raw_get("close")?;
|
||||||
|
lua.set_named_registry_value("coroutine.close", close)?;
|
||||||
lua.globals().raw_set(
|
lua.globals().raw_set(
|
||||||
"task",
|
"task",
|
||||||
TableBuilder::new(lua)?
|
TableBuilder::new(lua)?
|
||||||
|
@ -77,9 +82,8 @@ async fn run_registered_task(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn task_cancel<'a>(lua: &'a Lua, thread: LuaThread<'a>) -> LuaResult<()> {
|
async fn task_cancel<'a>(lua: &'a Lua, thread: LuaThread<'a>) -> LuaResult<()> {
|
||||||
let coroutine: LuaTable = lua.globals().raw_get("coroutine")?;
|
let close: LuaFunction = lua.named_registry_value("coroutine.close")?;
|
||||||
let close: LuaFunction = coroutine.raw_get("close")?;
|
close.call_async::<_, LuaMultiValue>(thread).await?;
|
||||||
close.call_async(thread).await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue