Skip to content

Commit 5bbd23e

Browse files
committed
Fix hook tests
1 parent 74b4601 commit 5bbd23e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/state/raw.rs

+2
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ impl RawLua {
411411
unsafe extern "C-unwind" fn global_hook_proc(state: *mut ffi::lua_State, ar: *mut ffi::lua_Debug) {
412412
let status = callback_error_ext(state, ptr::null_mut(), move |extra, _| {
413413
let rawlua = (*extra).raw_lua();
414+
let _guard = StateGuard::new(rawlua, state);
414415
let debug = Debug::new(rawlua, ar);
415416
match (*extra).hook_callback.take() {
416417
Some(hook_cb) => {
@@ -440,6 +441,7 @@ impl RawLua {
440441

441442
let status = callback_error_ext(state, ptr::null_mut(), |extra, _| {
442443
let rawlua = (*extra).raw_lua();
444+
let _guard = StateGuard::new(rawlua, state);
443445
let debug = Debug::new(rawlua, ar);
444446
match get_internal_userdata::<HookCallback>(state, -1, ptr::null()).as_ref() {
445447
Some(hook_cb) => hook_cb((*extra).lua(), debug),

tests/async.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,10 @@ async fn test_async_hook() -> Result<()> {
608608
static HOOK_CALLED: AtomicBool = AtomicBool::new(false);
609609
lua.set_global_hook(mlua::HookTriggers::new().every_line(), move |_, _| {
610610
if !HOOK_CALLED.swap(true, Ordering::Relaxed) {
611-
Ok(mlua::VmState::Yield)
612-
} else {
613-
Ok(mlua::VmState::Continue)
611+
#[cfg(any(feature = "lu53", feature = "lua54"))]
612+
return Ok(mlua::VmState::Yield);
614613
}
614+
Ok(mlua::VmState::Continue)
615615
})?;
616616

617617
let sleep = lua.create_async_function(move |_lua, n: u64| async move {

0 commit comments

Comments
 (0)