Skip to content

Commit d06ec39

Browse files
committed
Update debug docs
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
1 parent 1cb1f1c commit d06ec39

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/Debug.zig

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
//! Debug functionality for Luau scripts.
22
//!
3-
//! This module provides debugging support for Luau scripts, including breakpoints,
4-
//! single-stepping, and execution interruption. The debug system uses a callback-based
5-
//! approach where the VM notifies your application when debug events occur.
3+
//! This module provides comprehensive debugging support for Luau scripts with
4+
//! execution control, call stack inspection, and variable manipulation. Luau uses
5+
//! a callback-based approach where the VM notifies your application when debug
6+
//! events occur.
7+
//!
8+
//! ## Core APIs
9+
//!
10+
//! ### Execution Control
11+
//! - `setSingleStep()` - Enable/disable single-step debugging mode
12+
//! - `debugBreak()` - Interrupt thread execution during debug callbacks
13+
//! - `debugTrace()` - Get formatted stack traces for error reporting
14+
//! - `stackDepth()` - Get current call stack depth
15+
//!
16+
//! ### Stack Inspection
17+
//! - `getInfo()` - Get debug information about functions on the call stack
18+
//! - `getArg()` - Get function arguments at specific stack levels
19+
//! - `getLocal()`/`setLocal()` - Get/set local variables (requires debug level 2)
20+
//! - `getUpvalue()`/`setUpvalue()` - Get/set function upvalues (names require debug level 2)
621
//!
722
//! ## Debug Level Requirement
823
//!
9-
//! For local variable inspection (`getLocal`/`setLocal`) to work, Lua code must be
10-
//! compiled with debug level 2. This provides full debug information including
11-
//! local and upvalue names:
24+
//! For local variable and upvalue name inspection (`getLocal`/`setLocal`/`getUpvalue`/`setUpvalue`)
25+
//! to work fully, Lua code must be compiled with debug level 2. This provides full debug
26+
//! information including local and upvalue names:
1227
//!
1328
//! ```zig
1429
//! const Compiler = @import("Compiler.zig");
@@ -33,7 +48,7 @@
3348
//! 4. Breakpoint hits → VM calls your `debugbreak` callback
3449
//! 5. Interrupt execution → Call `debug.debugBreak()` within callback to pause
3550
//! 6. Handle interruption → Function returns `error.Break` to your application
36-
//! 7. Examine state → Use `getInfo()`, `stackDepth()`, etc. to inspect execution
51+
//! 7. Examine state → Use `getInfo()`, `stackDepth()`, `getArg()`, `getLocal()`, etc. to inspect execution
3752
//! 8. Resume execution → Call the function again to continue from where it left off
3853
//!
3954
//! ## Key Concepts
@@ -42,7 +57,7 @@
4257
//! - debugBreak() interrupts execution: Must be called within callbacks to actually stop
4358
//! - Resumption: After `error.Break`, call the same function again to resume
4459
//! - Field safety: Only request fields you need in `getInfo()` to avoid garbage data
45-
//! - Context flexibility: `getInfo()` and `stackDepth()` work everywhere
60+
//! - Context flexibility: `getInfo()`, `stackDepth()`, `getArg()`, `getLocal()`, and `getUpvalue()` work everywhere
4661
//!
4762
//! ## Setting Up Debug Callbacks
4863
//!
@@ -105,7 +120,7 @@
105120
//!
106121
//! ## Inspecting Call Stack
107122
//!
108-
//! Use `getInfo()`, `getArg()`, `getLocal()`, and `getUpvalue()` to examine the call stack at any time:
123+
//! Use `getInfo()`, `getArg()`, `getLocal()`, `setLocal()`, `getUpvalue()`, and `setUpvalue()` to examine and modify the call stack at any time:
109124
//! ```zig
110125
//! const debug = lua.debug();
111126
//! const depth = debug.stackDepth();

0 commit comments

Comments
 (0)