Skip to content

Commit

Permalink
Fix hook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khvzak committed Feb 8, 2025
1 parent 74b4601 commit 5bbd23e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/state/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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::<HookCallback>(state, -1, ptr::null()).as_ref() {
Some(hook_cb) => hook_cb((*extra).lua(), debug),
Expand Down
6 changes: 3 additions & 3 deletions tests/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5bbd23e

Please sign in to comment.