@@ -55,15 +55,13 @@ where
55
55
res
56
56
}
57
57
58
- // Run an operation on a lua_State and automatically clean up the stack before
59
- // returning. Takes the lua_State, the expected stack size change, and an
60
- // operation to run. If the operation results in success, then the stack is
61
- // inspected to make sure the change in stack size matches the expected change
62
- // and otherwise this is a logic error and will panic. If the operation results
63
- // in an error, the stack is shrunk to the value before the call. If the
64
- // operation results in an error and the stack is smaller than the value before
65
- // the call, then this is unrecoverable and this will panic. If this function
66
- // panics, it will clear the stack before panicking.
58
+ // Run an operation on a lua_State and automatically clean up the stack before returning. Takes the
59
+ // lua_State, the expected stack size change, and an operation to run. If the operation results in
60
+ // success, then the stack is inspected to make sure the change in stack size matches the expected
61
+ // change and otherwise this is a logic error and will panic. If the operation results in an error,
62
+ // the stack is shrunk to the value before the call. If the operation results in an error and the
63
+ // stack is smaller than the value before the call, then this is unrecoverable and this will panic.
64
+ // If this function panics, it will clear the stack before panicking.
67
65
pub unsafe fn stack_err_guard < F , R > ( state : * mut ffi:: lua_State , change : c_int , op : F ) -> Result < R >
68
66
where
69
67
F : FnOnce ( ) -> Result < R > ,
@@ -312,10 +310,13 @@ where
312
310
// traceback, and if it is a WrappedPanic, does not modify it.
313
311
#[ cfg_attr( unwind, unwind) ]
314
312
pub unsafe extern "C" fn error_traceback ( state : * mut ffi:: lua_State ) -> c_int {
313
+ // I believe luaL_traceback requires this much free stack to not error.
314
+ const LUA_TRACEBACK_STACK : c_int = 11 ;
315
+
315
316
if ffi:: lua_checkstack ( state, 2 ) == 0 {
316
317
// If we don't have enough stack space to even check the error type, do nothing
317
318
} else if is_wrapped_error ( state, 1 ) {
318
- let traceback = if ffi:: lua_checkstack ( state, 11 ) != 0 {
319
+ let traceback = if ffi:: lua_checkstack ( state, LUA_TRACEBACK_STACK ) != 0 {
319
320
gc_guard ( state, || {
320
321
ffi:: luaL_traceback ( state, state, ptr:: null ( ) , 0 ) ;
321
322
} ) ;
@@ -337,7 +338,7 @@ pub unsafe extern "C" fn error_traceback(state: *mut ffi::lua_State) -> c_int {
337
338
} ,
338
339
) ;
339
340
} else if !is_wrapped_panic ( state, 1 ) {
340
- if ffi:: lua_checkstack ( state, 11 ) != 0 {
341
+ if ffi:: lua_checkstack ( state, LUA_TRACEBACK_STACK ) != 0 {
341
342
gc_guard ( state, || {
342
343
let s = ffi:: lua_tostring ( state, 1 ) ;
343
344
let s = if s. is_null ( ) {
0 commit comments