Assert stack for Luau in callback_error_ext when operating on a cached wrapped failure.

Should solve #153.
This commit is contained in:
Alex Orlenko 2022-04-27 00:16:31 +01:00
parent 32a3f478bd
commit bea9b0f8b5
No known key found for this signature in database
GPG key ID: 4C150C250863B96D

View file

@ -2910,6 +2910,18 @@ where
let nargs = ffi::lua_gettop(state);
// We need 2 extra stack spaces to store userdata and error/panic metatable.
// Luau workaround can be removed after solving https://github.com/Roblox/luau/issues/446
// Also see #142 and #153
if !cfg!(feature = "luau") || extra.wrapped_failures_cache.is_empty() {
let extra_stack = if nargs < 2 { 2 - nargs } else { 1 };
ffi::luaL_checkstack(
state,
extra_stack,
cstr!("not enough stack space for callback error handling"),
);
}
enum PreallocatedFailure {
New(*mut WrappedFailure),
Cached(i32),
@ -2920,13 +2932,6 @@ where
let prealloc_failure = match extra.wrapped_failures_cache.pop() {
Some(index) => PreallocatedFailure::Cached(index),
None => {
// We need 2 extra stack spaces to store userdata and error/panic metatable.
let extra_stack = if nargs < 2 { 2 - nargs } else { 1 };
ffi::luaL_checkstack(
state,
extra_stack,
cstr!("not enough stack space for callback error handling"),
);
let ud = WrappedFailure::new_userdata(state);
ffi::lua_rotate(state, 1, 1);
PreallocatedFailure::New(ud)
@ -2940,6 +2945,8 @@ where
}
PreallocatedFailure::Cached(index) => {
ffi::lua_settop(state, 0);
#[cfg(feature = "luau")]
assert_stack(state, 2);
ffi::lua_pushvalue(extra.ref_thread, index);
ffi::lua_xmove(extra.ref_thread, state, 1);
ffi::lua_pushnil(extra.ref_thread);