summaryrefslogtreecommitdiff
path: root/src/thread.rs
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2022-07-31 15:33:02 +0100
committerAlex Orlenko <zxteam@protonmail.com>2022-07-31 15:33:02 +0100
commitab029b087d79e876e5e371be63c3cd96c734eeb5 (patch)
tree3c5e0623d944752c8abc30dc5e558e1afa97311f /src/thread.rs
parent185fee956dac0674b583db18c5c243537dca08da (diff)
downloadmlua-ab029b087d79e876e5e371be63c3cd96c734eeb5.zip
Close to-be-closed variables for Lua 5.4 when using call_async functions
Fixes #192
Diffstat (limited to 'src/thread.rs')
-rw-r--r--src/thread.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/thread.rs b/src/thread.rs
index dcdb565..6feab48 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -357,7 +357,16 @@ impl<'lua, R> Drop for AsyncThread<'lua, R> {
fn drop(&mut self) {
if self.recycle {
unsafe {
- self.thread.0.lua.recycle_thread(&mut self.thread);
+ let lua = self.thread.0.lua;
+ // For Lua 5.4 this also closes all pending to-be-closed variables
+ if !lua.recycle_thread(&mut self.thread) {
+ #[cfg(feature = "lua54")]
+ if self.thread.status() == ThreadStatus::Error {
+ let thread_state =
+ lua.ref_thread_exec(|t| ffi::lua_tothread(t, self.thread.0.index));
+ ffi::lua_resetthread(thread_state);
+ }
+ }
}
}
}