1
1
use std:: borrow:: Cow ;
2
2
use std:: os:: raw:: c_int;
3
3
4
- use ffi:: lua_Debug;
4
+ use ffi:: { lua_Debug, lua_State } ;
5
5
6
6
use crate :: state:: RawLua ;
7
7
use 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};
15
15
///
16
16
/// [documentation]: https://www.lua.org/manual/5.4/manual.html#lua_Debug
17
17
/// [`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 ,
20
20
#[ cfg_attr( not( feature = "luau" ) , allow( unused) ) ]
21
21
level : c_int ,
22
22
ar : * mut lua_Debug ,
23
23
}
24
24
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 }
28
29
}
29
30
30
31
/// Returns the specific event that triggered the hook.
@@ -53,12 +54,12 @@ impl<'a> Debug<'a> {
53
54
unsafe {
54
55
#[ cfg( not( feature = "luau" ) ) ]
55
56
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 ,
57
58
"lua_getinfo failed with `n`"
58
59
) ;
59
60
#[ cfg( feature = "luau" ) ]
60
61
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 ,
62
63
"lua_getinfo failed with `n`"
63
64
) ;
64
65
@@ -80,12 +81,12 @@ impl<'a> Debug<'a> {
80
81
unsafe {
81
82
#[ cfg( not( feature = "luau" ) ) ]
82
83
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 ,
84
85
"lua_getinfo failed with `S`"
85
86
) ;
86
87
#[ cfg( feature = "luau" ) ]
87
88
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 ,
89
90
"lua_getinfo failed with `s`"
90
91
) ;
91
92
@@ -110,12 +111,12 @@ impl<'a> Debug<'a> {
110
111
unsafe {
111
112
#[ cfg( not( feature = "luau" ) ) ]
112
113
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 ,
114
115
"lua_getinfo failed with `l`"
115
116
) ;
116
117
#[ cfg( feature = "luau" ) ]
117
118
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 ,
119
120
"lua_getinfo failed with `l`"
120
121
) ;
121
122
@@ -130,7 +131,7 @@ impl<'a> Debug<'a> {
130
131
pub fn is_tail_call ( & self ) -> bool {
131
132
unsafe {
132
133
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 ,
134
135
"lua_getinfo failed with `t`"
135
136
) ;
136
137
( * self . ar ) . currentline != 0
@@ -142,12 +143,12 @@ impl<'a> Debug<'a> {
142
143
unsafe {
143
144
#[ cfg( not( feature = "luau" ) ) ]
144
145
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 ,
146
147
"lua_getinfo failed with `u`"
147
148
) ;
148
149
#[ cfg( feature = "luau" ) ]
149
150
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 ,
151
152
"lua_getinfo failed with `au`"
152
153
) ;
153
154
0 commit comments