Skip to content

Commit 0e48990

Browse files
committed
Update debug module
Move debug types from root to new new module.
1 parent 88063e7 commit 0e48990

File tree

2 files changed

+32
-50
lines changed

2 files changed

+32
-50
lines changed

src/debug.rs

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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+
17
use std::borrow::Cow;
28
use 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)]
212214
pub 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)]
222227
pub 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)]
232240
pub 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)]
247258
pub 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,

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ mod macros;
7474
mod buffer;
7575
mod chunk;
7676
mod conversion;
77-
mod debug;
7877
mod error;
7978
#[cfg(any(feature = "luau", doc))]
8079
mod luau;
@@ -92,6 +91,7 @@ mod util;
9291
mod value;
9392
mod vector;
9493

94+
pub mod debug;
9595
pub mod function;
9696
pub mod prelude;
9797
pub mod table;
@@ -100,7 +100,6 @@ pub use bstr::BString;
100100
pub use ffi::{self, lua_CFunction, lua_State};
101101

102102
pub use crate::chunk::{AsChunk, Chunk, ChunkMode};
103-
pub use crate::debug::{Debug, DebugEvent, DebugNames, DebugSource, DebugStack};
104103
pub use crate::error::{Error, ErrorContext, ExternalError, ExternalResult, Result};
105104
pub use crate::function::Function;
106105
pub use crate::multi::{MultiValue, Variadic};

0 commit comments

Comments
 (0)