@@ -105,7 +105,7 @@ where
105
105
// limited lua stack. `nargs` and `nresults` are similar to the parameters of `lua_pcall`, but the
106
106
// given function return type is not the return value count, instead the inner function return
107
107
// values are assumed to match the `nresults` param. Internally uses 3 extra stack spaces, and does
108
- // not call checkstack.
108
+ // not call checkstack. Provided function must *not* panic.
109
109
pub unsafe fn protect_lua_call < F , R > (
110
110
state : * mut ffi:: lua_State ,
111
111
nargs : c_int ,
@@ -121,6 +121,7 @@ where
121
121
nresults : c_int ,
122
122
}
123
123
124
+ #[ cfg_attr( feature = "unwind" , unwind) ]
124
125
unsafe extern "C" fn do_call < F , R > ( state : * mut ffi:: lua_State ) -> c_int
125
126
where
126
127
F : FnOnce ( * mut ffi:: lua_State ) -> R ,
@@ -271,6 +272,7 @@ pub unsafe fn take_userdata<T>(state: *mut ffi::lua_State) -> T {
271
272
ptr:: read ( ud)
272
273
}
273
274
275
+ #[ cfg_attr( feature = "unwind" , unwind) ]
274
276
pub unsafe extern "C" fn userdata_destructor < T > ( state : * mut ffi:: lua_State ) -> c_int {
275
277
callback_error ( state, || {
276
278
take_userdata :: < T > ( state) ;
@@ -291,11 +293,13 @@ where
291
293
Ok ( Err ( err) ) => {
292
294
ffi:: luaL_checkstack ( state, 2 , ptr:: null ( ) ) ;
293
295
push_wrapped_error ( state, err) ;
296
+ println ! ( "erroring..." ) ;
294
297
ffi:: lua_error ( state)
295
298
}
296
299
Err ( p) => {
297
300
ffi:: luaL_checkstack ( state, 2 , ptr:: null ( ) ) ;
298
301
push_wrapped_panic ( state, p) ;
302
+ println ! ( "erroring..." ) ;
299
303
ffi:: lua_error ( state)
300
304
}
301
305
}
@@ -304,6 +308,7 @@ where
304
308
// Takes an error at the top of the stack, and if it is a WrappedError, converts it to an
305
309
// Error::CallbackError with a traceback, if it is some lua type, prints the error along with a
306
310
// traceback, and if it is a WrappedPanic, does not modify it.
311
+ #[ cfg_attr( feature = "unwind" , unwind) ]
307
312
pub unsafe extern "C" fn error_traceback ( state : * mut ffi:: lua_State ) -> c_int {
308
313
ffi:: luaL_checkstack ( state, 2 , ptr:: null ( ) ) ;
309
314
@@ -334,6 +339,7 @@ pub unsafe extern "C" fn error_traceback(state: *mut ffi::lua_State) -> c_int {
334
339
}
335
340
336
341
// A variant of pcall that does not allow lua to catch panic errors from callback_error
342
+ #[ cfg_attr( feature = "unwind" , unwind) ]
337
343
pub unsafe extern "C" fn safe_pcall ( state : * mut ffi:: lua_State ) -> c_int {
338
344
ffi:: luaL_checkstack ( state, 2 , ptr:: null ( ) ) ;
339
345
@@ -356,7 +362,9 @@ pub unsafe extern "C" fn safe_pcall(state: *mut ffi::lua_State) -> c_int {
356
362
}
357
363
358
364
// A variant of xpcall that does not allow lua to catch panic errors from callback_error
365
+ #[ cfg_attr( feature = "unwind" , unwind) ]
359
366
pub unsafe extern "C" fn safe_xpcall ( state : * mut ffi:: lua_State ) -> c_int {
367
+ #[ cfg_attr( feature = "unwind" , unwind) ]
360
368
unsafe extern "C" fn xpcall_msgh ( state : * mut ffi:: lua_State ) -> c_int {
361
369
ffi:: luaL_checkstack ( state, 2 , ptr:: null ( ) ) ;
362
370
@@ -504,6 +512,7 @@ unsafe fn is_wrapped_panic(state: *mut ffi::lua_State, index: c_int) -> bool {
504
512
unsafe fn get_error_metatable ( state : * mut ffi:: lua_State ) -> c_int {
505
513
static ERROR_METATABLE_REGISTRY_KEY : u8 = 0 ;
506
514
515
+ #[ cfg_attr( feature = "unwind" , unwind) ]
507
516
unsafe extern "C" fn error_tostring ( state : * mut ffi:: lua_State ) -> c_int {
508
517
ffi:: luaL_checkstack ( state, 2 , ptr:: null ( ) ) ;
509
518
@@ -605,6 +614,7 @@ unsafe fn get_panic_metatable(state: *mut ffi::lua_State) -> c_int {
605
614
unsafe fn get_destructed_userdata_metatable ( state : * mut ffi:: lua_State ) -> c_int {
606
615
static DESTRUCTED_USERDATA_METATABLE : u8 = 0 ;
607
616
617
+ #[ cfg_attr( feature = "unwind" , unwind) ]
608
618
unsafe extern "C" fn destructed_error ( state : * mut ffi:: lua_State ) -> c_int {
609
619
ffi:: luaL_checkstack ( state, 2 , ptr:: null ( ) ) ;
610
620
push_wrapped_error ( state, Error :: CallbackDestructed ) ;
0 commit comments