11use std:: borrow:: Cow ;
22use std:: os:: raw:: c_int;
33
4- use ffi:: lua_Debug;
4+ use ffi:: { lua_Debug, lua_State } ;
55
66use crate :: state:: RawLua ;
77use crate :: util:: { linenumber_to_usize, ptr_to_lossy_str, ptr_to_str} ;
@@ -15,16 +15,17 @@ use crate::util::{linenumber_to_usize, ptr_to_lossy_str, ptr_to_str};
1515///
1616/// [documentation]: https://www.lua.org/manual/5.4/manual.html#lua_Debug
1717/// [`Lua::set_hook`]: crate::Lua::set_hook
18- pub struct Debug < ' a > {
19- lua : & ' a RawLua ,
18+ pub struct Debug {
19+ state : * mut lua_State ,
2020 #[ cfg_attr( not( feature = "luau" ) , allow( unused) ) ]
2121 level : c_int ,
2222 ar : * mut lua_Debug ,
2323}
2424
25- impl < ' a > Debug < ' a > {
26- pub ( crate ) fn new ( lua : & ' a RawLua , level : c_int , ar : * mut lua_Debug ) -> Self {
27- Debug { lua, ar, level }
25+ impl Debug {
26+ pub ( crate ) fn new ( lua : & RawLua , level : c_int , ar : * mut lua_Debug ) -> Self {
27+ let state = lua. state ( ) ;
28+ Debug { state, ar, level }
2829 }
2930
3031 /// Returns the specific event that triggered the hook.
@@ -53,12 +54,12 @@ impl<'a> Debug<'a> {
5354 unsafe {
5455 #[ cfg( not( feature = "luau" ) ) ]
5556 mlua_assert ! (
56- ffi:: lua_getinfo( self . lua . state( ) , cstr!( "n" ) , self . ar) != 0 ,
57+ ffi:: lua_getinfo( self . state, cstr!( "n" ) , self . ar) != 0 ,
5758 "lua_getinfo failed with `n`"
5859 ) ;
5960 #[ cfg( feature = "luau" ) ]
6061 mlua_assert ! (
61- ffi:: lua_getinfo( self . lua . state( ) , self . level, cstr!( "n" ) , self . ar) != 0 ,
62+ ffi:: lua_getinfo( self . state, self . level, cstr!( "n" ) , self . ar) != 0 ,
6263 "lua_getinfo failed with `n`"
6364 ) ;
6465
@@ -80,12 +81,12 @@ impl<'a> Debug<'a> {
8081 unsafe {
8182 #[ cfg( not( feature = "luau" ) ) ]
8283 mlua_assert ! (
83- ffi:: lua_getinfo( self . lua . state( ) , cstr!( "S" ) , self . ar) != 0 ,
84+ ffi:: lua_getinfo( self . state, cstr!( "S" ) , self . ar) != 0 ,
8485 "lua_getinfo failed with `S`"
8586 ) ;
8687 #[ cfg( feature = "luau" ) ]
8788 mlua_assert ! (
88- ffi:: lua_getinfo( self . lua . state( ) , self . level, cstr!( "s" ) , self . ar) != 0 ,
89+ ffi:: lua_getinfo( self . state, self . level, cstr!( "s" ) , self . ar) != 0 ,
8990 "lua_getinfo failed with `s`"
9091 ) ;
9192
@@ -110,12 +111,12 @@ impl<'a> Debug<'a> {
110111 unsafe {
111112 #[ cfg( not( feature = "luau" ) ) ]
112113 mlua_assert ! (
113- ffi:: lua_getinfo( self . lua . state( ) , cstr!( "l" ) , self . ar) != 0 ,
114+ ffi:: lua_getinfo( self . state, cstr!( "l" ) , self . ar) != 0 ,
114115 "lua_getinfo failed with `l`"
115116 ) ;
116117 #[ cfg( feature = "luau" ) ]
117118 mlua_assert ! (
118- ffi:: lua_getinfo( self . lua . state( ) , self . level, cstr!( "l" ) , self . ar) != 0 ,
119+ ffi:: lua_getinfo( self . state, self . level, cstr!( "l" ) , self . ar) != 0 ,
119120 "lua_getinfo failed with `l`"
120121 ) ;
121122
@@ -130,7 +131,7 @@ impl<'a> Debug<'a> {
130131 pub fn is_tail_call ( & self ) -> bool {
131132 unsafe {
132133 mlua_assert ! (
133- ffi:: lua_getinfo( self . lua . state( ) , cstr!( "t" ) , self . ar) != 0 ,
134+ ffi:: lua_getinfo( self . state, cstr!( "t" ) , self . ar) != 0 ,
134135 "lua_getinfo failed with `t`"
135136 ) ;
136137 ( * self . ar ) . currentline != 0
@@ -142,12 +143,12 @@ impl<'a> Debug<'a> {
142143 unsafe {
143144 #[ cfg( not( feature = "luau" ) ) ]
144145 mlua_assert ! (
145- ffi:: lua_getinfo( self . lua . state( ) , cstr!( "u" ) , self . ar) != 0 ,
146+ ffi:: lua_getinfo( self . state, cstr!( "u" ) , self . ar) != 0 ,
146147 "lua_getinfo failed with `u`"
147148 ) ;
148149 #[ cfg( feature = "luau" ) ]
149150 mlua_assert ! (
150- ffi:: lua_getinfo( self . lua . state( ) , self . level, cstr!( "au" ) , self . ar) != 0 ,
151+ ffi:: lua_getinfo( self . state, self . level, cstr!( "au" ) , self . ar) != 0 ,
151152 "lua_getinfo failed with `au`"
152153 ) ;
153154
0 commit comments