Implement thread creation deletion event callback.#506
Implement thread creation deletion event callback.#506radiantgurl wants to merge 1 commit intomlua-rs:mainfrom
Conversation
4b21fc5 to
39a39d4
Compare
494cc56 to
09a55f2
Compare
|
This would be useful |
I know, and since I felt like others would also want it i decided to open a pull request. |
|
Thanks for the PR, I'll review it soon |
40a8676 to
e84bce1
Compare
| if self.unlikely_memory_error() { | ||
| ffi::lua_pushthread(ref_thread) | ||
| } else { | ||
| protect_lua!(ref_thread, 0, 1, |ref_thread| ffi::lua_pushthread(ref_thread))? | ||
| }; |
| let main_extra = ExtraData::get(main_state); | ||
| let main_raw_lua: &RawLua = (*main_extra).raw_lua(); | ||
| let _guard = StateGuard::new(main_raw_lua, state); |
There was a problem hiding this comment.
RawLua is singleton, it never changes (as well as ExtraData instance)
| value.push_into_stack(self) | ||
| } | ||
|
|
||
| pub(crate) unsafe fn push_ref_thread(&self, ref_thread: *mut ffi::lua_State) -> Result<()> { |
There was a problem hiding this comment.
ref_thread seems misleading name here, it cannot be the reference thread (as it's a very special type of thread used internally)
| unsafe extern "C-unwind" fn userthread_proc(parent: *mut ffi::lua_State, state: *mut ffi::lua_State) { | ||
| callback_error_ext(state, ptr::null_mut(), move |extra, _| { | ||
| let raw_lua: &RawLua = (*extra).raw_lua(); | ||
| let _guard = StateGuard::new(raw_lua, state); |
There was a problem hiding this comment.
Hmm, why we need to switch state here?
| let userthread_cb = | ||
| mlua_expect!(userthread_cb, "no userthread callback set in userthread_proc"); | ||
| if parent.is_null() { | ||
| raw_lua.push(Value::Nil).unwrap(); |
There was a problem hiding this comment.
seems this stack value is never used ?
| let _guard = StateGuard::new(main_raw_lua, state); | ||
| userthread_cb((*main_extra).lua(), event_info) | ||
| } else { | ||
| raw_lua.push_ref_thread(parent).unwrap(); |
| /// When a thread is created, it contains the thread that created it. | ||
| Created(Thread), |
There was a problem hiding this comment.
Should it be vice versa? The thread that was created, not parent.
|
any updates to this PR? |
I'm currently caught up in a situation IRL so it will take a while. |
|
Hey, this could've been marked back to a draft, I dont understand why it was closed? |
|
This feature landed to mlua, 1f97082 |
No description provided.