Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread::set_hook only effective for the last time #489

Open
rise0chen opened this issue Nov 27, 2024 · 2 comments · May be fixed by #498
Open

Thread::set_hook only effective for the last time #489

rise0chen opened this issue Nov 27, 2024 · 2 comments · May be fixed by #498

Comments

@rise0chen
Copy link
Contributor

rise0chen commented Nov 27, 2024

use futures_util::future::join_all;
use mlua::prelude::*;

#[tokio::main(flavor = "current_thread")]
async fn main() -> LuaResult<()> {
    let lua = Lua::new();
    let func = lua
        .load(
            r#"
            local x = 2 + 3
            local y = x * 63
            local z = string.len(x..", "..y)
        "#,
        )
        .into_function()?;

    let mut cos: Vec<LuaAsyncThread<_, ()>> = Vec::new();
    for i in 0..3 {
        let thread = lua.create_thread(func.clone())?;
        thread.set_hook(LuaHookTriggers::EVERY_LINE, move |_lua, _debug| {
            println!("test hook {}", i);
            Ok(LuaVmState::Continue)
        });
        cos.push(thread.into_async(()));
    }
    join_all(cos).await;

    lua.remove_hook();

    Ok(())
}

image

It not print test hook 0 and test hook 1

@rise0chen
Copy link
Contributor Author

set_hook is global in v0.6.

set hook for every coroutine can't work in new version.
#347

@rise0chen
Copy link
Contributor Author

I think global is more concise and more practical, even if it doesn't comply with Lua rules.

@rise0chen rise0chen linked a pull request Dec 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant