|
1 | 1 | //! Debug functionality for Luau scripts. |
2 | 2 | //! |
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) |
6 | 21 | //! |
7 | 22 | //! ## Debug Level Requirement |
8 | 23 | //! |
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: |
12 | 27 | //! |
13 | 28 | //! ```zig |
14 | 29 | //! const Compiler = @import("Compiler.zig"); |
|
33 | 48 | //! 4. Breakpoint hits → VM calls your `debugbreak` callback |
34 | 49 | //! 5. Interrupt execution → Call `debug.debugBreak()` within callback to pause |
35 | 50 | //! 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 |
37 | 52 | //! 8. Resume execution → Call the function again to continue from where it left off |
38 | 53 | //! |
39 | 54 | //! ## Key Concepts |
|
42 | 57 | //! - debugBreak() interrupts execution: Must be called within callbacks to actually stop |
43 | 58 | //! - Resumption: After `error.Break`, call the same function again to resume |
44 | 59 | //! - 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 |
46 | 61 | //! |
47 | 62 | //! ## Setting Up Debug Callbacks |
48 | 63 | //! |
|
105 | 120 | //! |
106 | 121 | //! ## Inspecting Call Stack |
107 | 122 | //! |
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: |
109 | 124 | //! ```zig |
110 | 125 | //! const debug = lua.debug(); |
111 | 126 | //! const depth = debug.stackDepth(); |
|
0 commit comments