From 5bbd23ed1a9e23f5d74c303d6c7d7498e81467cd Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 8 Feb 2025 11:51:38 +0000 Subject: [PATCH] Fix hook tests --- src/state/raw.rs | 2 ++ tests/async.rs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/state/raw.rs b/src/state/raw.rs index ff0e4a7e..f5bf7280 100644 --- a/src/state/raw.rs +++ b/src/state/raw.rs @@ -411,6 +411,7 @@ impl RawLua { unsafe extern "C-unwind" fn global_hook_proc(state: *mut ffi::lua_State, ar: *mut ffi::lua_Debug) { let status = callback_error_ext(state, ptr::null_mut(), move |extra, _| { let rawlua = (*extra).raw_lua(); + let _guard = StateGuard::new(rawlua, state); let debug = Debug::new(rawlua, ar); match (*extra).hook_callback.take() { Some(hook_cb) => { @@ -440,6 +441,7 @@ impl RawLua { let status = callback_error_ext(state, ptr::null_mut(), |extra, _| { let rawlua = (*extra).raw_lua(); + let _guard = StateGuard::new(rawlua, state); let debug = Debug::new(rawlua, ar); match get_internal_userdata::(state, -1, ptr::null()).as_ref() { Some(hook_cb) => hook_cb((*extra).lua(), debug), diff --git a/tests/async.rs b/tests/async.rs index ce2bae6b..6ae3b3de 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -608,10 +608,10 @@ async fn test_async_hook() -> Result<()> { static HOOK_CALLED: AtomicBool = AtomicBool::new(false); lua.set_global_hook(mlua::HookTriggers::new().every_line(), move |_, _| { if !HOOK_CALLED.swap(true, Ordering::Relaxed) { - Ok(mlua::VmState::Yield) - } else { - Ok(mlua::VmState::Continue) + #[cfg(any(feature = "lu53", feature = "lua54"))] + return Ok(mlua::VmState::Yield); } + Ok(mlua::VmState::Continue) })?; let sleep = lua.create_async_function(move |_lua, n: u64| async move {