(Luau) Set thread globals to main thread globals when resetting the thread
This commit is contained in:
parent
a1089dbf95
commit
c905a34b1d
|
@ -3006,6 +3006,12 @@ impl LuaInner {
|
|||
self.state.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
#[cfg(feature = "luau")]
|
||||
#[inline(always)]
|
||||
pub(crate) fn main_state(&self) -> *mut ffi::lua_State {
|
||||
self.main_state
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn ref_thread(&self) -> *mut ffi::lua_State {
|
||||
unsafe { (*self.extra.get()).ref_thread }
|
||||
|
|
|
@ -251,8 +251,8 @@ impl<'lua> Thread<'lua> {
|
|||
|
||||
#[cfg(feature = "luau")]
|
||||
{
|
||||
// Inherit `LUA_GLOBALSINDEX` from the caller
|
||||
ffi::lua_xpush(state, thread_state, ffi::LUA_GLOBALSINDEX);
|
||||
// Inherit `LUA_GLOBALSINDEX` from the main thread
|
||||
ffi::lua_xpush(lua.main_state(), thread_state, ffi::LUA_GLOBALSINDEX);
|
||||
ffi::lua_replace(thread_state, ffi::LUA_GLOBALSINDEX);
|
||||
}
|
||||
|
||||
|
@ -360,11 +360,8 @@ impl<'lua> Thread<'lua> {
|
|||
let state = lua.state();
|
||||
unsafe {
|
||||
let thread = ffi::lua_tothread(lua.ref_thread(), self.0.index);
|
||||
check_stack(thread, 1)?;
|
||||
check_stack(thread, 3)?;
|
||||
check_stack(state, 3)?;
|
||||
// Inherit `LUA_GLOBALSINDEX` from the caller
|
||||
ffi::lua_xpush(state, thread, ffi::LUA_GLOBALSINDEX);
|
||||
ffi::lua_replace(thread, ffi::LUA_GLOBALSINDEX);
|
||||
protect_lua!(state, 0, 0, |_| ffi::luaL_sandboxthread(thread))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue