@@ -31,10 +31,10 @@ use crate::types::{
31
31
use crate :: userdata:: { AnyUserData , MetaMethod , UserData , UserDataCell } ;
32
32
use crate :: userdata_impl:: { UserDataProxy , UserDataRegistry } ;
33
33
use crate :: util:: {
34
- self , assert_stack, check_stack, get_destructed_userdata_metatable , get_gc_metatable ,
35
- get_gc_userdata, get_main_state, get_userdata, init_error_registry, init_gc_metatable ,
36
- init_userdata_metatable, pop_error, push_gc_userdata, push_string, push_table , rawset_field ,
37
- safe_pcall, safe_xpcall, short_type_name, StackGuard , WrappedFailure ,
34
+ self , assert_stack, check_stack, error_traceback , get_destructed_userdata_metatable ,
35
+ get_gc_metatable , get_gc_userdata, get_main_state, get_userdata, init_error_registry,
36
+ init_gc_metatable , init_userdata_metatable, pop_error, push_gc_userdata, push_string,
37
+ push_table , rawset_field , safe_pcall, safe_xpcall, short_type_name, StackGuard , WrappedFailure ,
38
38
} ;
39
39
use crate :: value:: { FromLua , FromLuaMulti , IntoLua , IntoLuaMulti , MultiValue , Nil , Value } ;
40
40
@@ -499,6 +499,13 @@ impl Lua {
499
499
ptr
500
500
} ;
501
501
502
+ // Store `error_traceback` function on the ref stack
503
+ #[ cfg( any( feature = "lua51" , feature = "luajit" , feature = "luau" ) ) ]
504
+ {
505
+ ffi:: lua_pushcfunction ( ref_thread, error_traceback) ;
506
+ assert_eq ! ( ffi:: lua_gettop( ref_thread) , ExtraData :: ERROR_TRACEBACK_IDX ) ;
507
+ }
508
+
502
509
// Create ExtraData
503
510
let extra = Arc :: new ( UnsafeCell :: new ( ExtraData {
504
511
inner : MaybeUninit :: uninit ( ) ,
@@ -2601,6 +2608,16 @@ impl Lua {
2601
2608
LuaRef :: new ( self , index)
2602
2609
}
2603
2610
2611
+ #[ inline]
2612
+ pub ( crate ) unsafe fn push_error_traceback ( & self ) {
2613
+ let state = self . state ( ) ;
2614
+ #[ cfg( any( feature = "lua51" , feature = "luajit" , feature = "luau" ) ) ]
2615
+ ffi:: lua_xpush ( self . ref_thread ( ) , state, ExtraData :: ERROR_TRACEBACK_IDX ) ;
2616
+ // Lua 5.2+ support light C functions that does not require extra allocations
2617
+ #[ cfg( any( feature = "lua54" , feature = "lua53" , feature = "lua52" ) ) ]
2618
+ ffi:: lua_pushcfunction ( state, error_traceback) ;
2619
+ }
2620
+
2604
2621
unsafe fn register_userdata_metatable < ' lua , T : ' static > (
2605
2622
& ' lua self ,
2606
2623
mut registry : UserDataRegistry < ' lua , T > ,
@@ -3211,6 +3228,12 @@ impl LuaInner {
3211
3228
}
3212
3229
}
3213
3230
3231
+ impl ExtraData {
3232
+ // Index of `error_traceback` function in auxiliary thread stack
3233
+ #[ cfg( any( feature = "lua51" , feature = "luajit" , feature = "luau" ) ) ]
3234
+ const ERROR_TRACEBACK_IDX : c_int = 1 ;
3235
+ }
3236
+
3214
3237
struct StateGuard < ' a > ( & ' a LuaInner , * mut ffi:: lua_State ) ;
3215
3238
3216
3239
impl < ' a > StateGuard < ' a > {
0 commit comments