1+ //! Lua debugging interface.
2+ //!
3+ //! This module provides access to the Lua debug interface, allowing inspection of the call stack,
4+ //! and function information. The main types are [`Debug`] for accessing debug information and
5+ //! [`HookTriggers`] for configuring debug hooks.
6+
17use std:: borrow:: Cow ;
28use std:: os:: raw:: c_int;
39
@@ -133,12 +139,6 @@ impl<'a> Debug<'a> {
133139 }
134140 }
135141
136- #[ doc( hidden) ]
137- #[ deprecated( note = "Use `current_line` instead" ) ]
138- pub fn curr_line ( & self ) -> i32 {
139- self . current_line ( ) . map ( |n| n as i32 ) . unwrap_or ( -1 )
140- }
141-
142142 /// Corresponds to the `l` "what" mask. Returns the current line.
143143 pub fn current_line ( & self ) -> Option < usize > {
144144 unsafe {
@@ -190,15 +190,15 @@ impl<'a> Debug<'a> {
190190
191191 #[ cfg( not( feature = "luau" ) ) ]
192192 let stack = DebugStack {
193- num_ups : ( * self . ar ) . nups as _ ,
194- #[ cfg( any( feature = "lua55 " , feature = "lua54" , feature = "lua53" , feature = "lua52" ) ) ]
193+ num_upvalues : ( * self . ar ) . nups as _ ,
194+ #[ cfg( not ( any( feature = "lua51 " , feature = "luajit" ) ) ) ]
195195 num_params : ( * self . ar ) . nparams as _ ,
196- #[ cfg( any( feature = "lua55 " , feature = "lua54" , feature = "lua53" , feature = "lua52" ) ) ]
196+ #[ cfg( not ( any( feature = "lua51 " , feature = "luajit" ) ) ) ]
197197 is_vararg : ( * self . ar ) . isvararg != 0 ,
198198 } ;
199199 #[ cfg( feature = "luau" ) ]
200200 let stack = DebugStack {
201- num_ups : ( * self . ar ) . nupvals ,
201+ num_upvalues : ( * self . ar ) . nupvals ,
202202 num_params : ( * self . ar ) . nparams ,
203203 is_vararg : ( * self . ar ) . isvararg != 0 ,
204204 } ;
@@ -208,6 +208,8 @@ impl<'a> Debug<'a> {
208208}
209209
210210/// Represents a specific event that triggered the hook.
211+ #[ cfg( not( feature = "luau" ) ) ]
212+ #[ cfg_attr( docsrs, doc( cfg( not( feature = "luau" ) ) ) ) ]
211213#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
212214pub enum DebugEvent {
213215 Call ,
@@ -218,6 +220,9 @@ pub enum DebugEvent {
218220 Unknown ( c_int ) ,
219221}
220222
223+ /// Contains the name information of a function in the call stack.
224+ ///
225+ /// Returned by the [`Debug::names`] method.
221226#[ derive( Clone , Debug ) ]
222227pub struct DebugNames < ' a > {
223228 /// A (reasonable) name of the function (`None` if the name cannot be found).
@@ -228,6 +233,9 @@ pub struct DebugNames<'a> {
228233 pub name_what : Option < & ' static str > ,
229234}
230235
236+ /// Contains the source information of a function in the call stack.
237+ ///
238+ /// Returned by the [`Debug::source`] method.
231239#[ derive( Clone , Debug ) ]
232240pub struct DebugSource < ' a > {
233241 /// Source of the chunk that created the function.
@@ -243,47 +251,20 @@ pub struct DebugSource<'a> {
243251 pub what : & ' static str ,
244252}
245253
254+ /// Contains stack information about a function in the call stack.
255+ ///
256+ /// Returned by the [`Debug::stack`] method.
246257#[ derive( Copy , Clone , Debug ) ]
247258pub struct DebugStack {
248- /// Number of upvalues.
249- pub num_ups : u8 ,
250- /// Number of parameters.
251- #[ cfg( any(
252- feature = "lua55" ,
253- feature = "lua54" ,
254- feature = "lua53" ,
255- feature = "lua52" ,
256- feature = "luau"
257- ) ) ]
258- #[ cfg_attr(
259- docsrs,
260- doc( cfg( any(
261- feature = "lua55" ,
262- feature = "lua54" ,
263- feature = "lua53" ,
264- feature = "lua52" ,
265- feature = "luau"
266- ) ) )
267- ) ]
259+ /// The number of upvalues of the function.
260+ pub num_upvalues : u8 ,
261+ /// The number of parameters of the function (always 0 for C).
262+ #[ cfg( any( not( any( feature = "lua51" , feature = "luajit" ) ) , doc) ) ]
263+ #[ cfg_attr( docsrs, doc( cfg( not( any( feature = "lua51" , feature = "luajit" ) ) ) ) ) ]
268264 pub num_params : u8 ,
269- /// Whether the function is a vararg function.
270- #[ cfg( any(
271- feature = "lua55" ,
272- feature = "lua54" ,
273- feature = "lua53" ,
274- feature = "lua52" ,
275- feature = "luau"
276- ) ) ]
277- #[ cfg_attr(
278- docsrs,
279- doc( cfg( any(
280- feature = "lua55" ,
281- feature = "lua54" ,
282- feature = "lua53" ,
283- feature = "lua52" ,
284- feature = "luau"
285- ) ) )
286- ) ]
265+ /// Whether the function is a variadic function (always true for C).
266+ #[ cfg( any( not( any( feature = "lua51" , feature = "luajit" ) ) , doc) ) ]
267+ #[ cfg_attr( docsrs, doc( cfg( not( any( feature = "lua51" , feature = "luajit" ) ) ) ) ) ]
287268 pub is_vararg : bool ,
288269}
289270
@@ -361,6 +342,7 @@ impl HookTriggers {
361342 }
362343
363344 // Compute the mask to pass to `lua_sethook`.
345+ #[ cfg( not( feature = "luau" ) ) ]
364346 pub ( crate ) const fn mask ( & self ) -> c_int {
365347 let mut mask: c_int = 0 ;
366348 if self . on_calls {
@@ -380,6 +362,7 @@ impl HookTriggers {
380362
381363 // Returns the `count` parameter to pass to `lua_sethook`, if applicable. Otherwise, zero is
382364 // returned.
365+ #[ cfg( not( feature = "luau" ) ) ]
383366 pub ( crate ) const fn count ( & self ) -> c_int {
384367 match self . every_nth_instruction {
385368 Some ( n) => n as c_int ,
0 commit comments