summaryrefslogtreecommitdiff
path: root/src/lua.rs
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2023-07-09 12:33:21 +0100
committerAlex Orlenko <zxteam@protonmail.com>2023-07-09 12:33:21 +0100
commit24e14c48740ca0903ba54247e4c8ba542726513d (patch)
tree2dc5b181d1c1c9acd45233ea4a17147f7a6f2f48 /src/lua.rs
parent20826a69ae90a2ac646e78a42e95e776338c8cfc (diff)
downloadmlua-24e14c48740ca0903ba54247e4c8ba542726513d.zip
Always set hook on a current Lua context (state) and remove MainThreadNotAvailable as no longer needed
Diffstat (limited to 'src/lua.rs')
-rw-r--r--src/lua.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/lua.rs b/src/lua.rs
index 21b8012..5edbcdf 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -836,8 +836,8 @@ impl Lua {
/// limited form of execution limits by setting [`HookTriggers.every_nth_instruction`] and
/// erroring once an instruction limit has been reached.
///
- /// This method sets a hook function for the main thread (if available) of this Lua instance.
- /// If you want to set a hook function for a thread (coroutine), use [`Thread::set_hook()`] instead.
+ /// This method sets a hook function for the current thread of this Lua instance.
+ /// If you want to set a hook function for another thread (coroutine), use [`Thread::set_hook()`] instead.
///
/// Please note you cannot have more than one hook function set at a time for this Lua instance.
///
@@ -852,7 +852,7 @@ impl Lua {
/// lua.set_hook(HookTriggers::EVERY_LINE, |_lua, debug| {
/// println!("line {}", debug.curr_line());
/// Ok(())
- /// })?;
+ /// });
///
/// lua.load(r#"
/// local x = 2 + 3
@@ -866,15 +866,11 @@ impl Lua {
/// [`HookTriggers.every_nth_instruction`]: crate::HookTriggers::every_nth_instruction
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
- pub fn set_hook<F>(&self, triggers: HookTriggers, callback: F) -> Result<()>
+ pub fn set_hook<F>(&self, triggers: HookTriggers, callback: F)
where
F: Fn(&Lua, Debug) -> Result<()> + MaybeSend + 'static,
{
- unsafe {
- let state = get_main_state(self.main_state).ok_or(Error::MainThreadNotAvailable)?;
- self.set_thread_hook(state, triggers, callback);
- }
- Ok(())
+ unsafe { self.set_thread_hook(self.state(), triggers, callback) };
}
/// Sets a 'hook' function for a thread (coroutine).