Skip to content

Commit 5f59b29

Browse files
committed
Add ability to get a handle to a Context's Thread
1 parent de8f828 commit 5f59b29

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/context.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ impl<'lua> Context<'lua> {
234234
}
235235
}
236236

237+
/// Returns a handle to the active `Thread` for this `Context`. For calls to `Lua::context`
238+
/// this will be the main Lua thread, for `Context` parameters given to a callback, this will be
239+
/// whatever Lua thread called the callback.
240+
pub fn current_thread(self) -> Thread<'lua> {
241+
unsafe {
242+
ffi::lua_pushthread(self.state);
243+
Thread(self.pop_ref())
244+
}
245+
}
246+
237247
/// Calls the given function with a `Scope` parameter, giving the function the ability to create
238248
/// userdata and callbacks from rust types that are !Send or non-'static.
239249
///

src/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ extern "C" {
118118
pub fn lua_pushstring(state: *mut lua_State, s: *const c_char) -> *const c_char;
119119
pub fn lua_pushlightuserdata(state: *mut lua_State, data: *mut c_void);
120120
pub fn lua_pushcclosure(state: *mut lua_State, function: lua_CFunction, n: c_int);
121+
pub fn lua_pushthread(state: *mut lua_State) -> c_int;
121122

122123
pub fn lua_tointegerx(state: *mut lua_State, index: c_int, isnum: *mut c_int) -> lua_Integer;
123124
pub fn lua_tolstring(state: *mut lua_State, index: c_int, len: *mut usize) -> *const c_char;

0 commit comments

Comments
 (0)