feat(lua): Python-style traceback + locals capture#448
Open
skhaz wants to merge 1 commit into
Open
Conversation
Why: Lua scripts on Wippy had no way to capture a stack trace with local variables — only a bare debug.traceback string with no locals, and even that was unavailable because SkipOpenLibs excluded the debug library entirely. This adds Python-style traceback + locals capture, on demand, for debugging and error handlers. What: - Expose a read-only debug subset as a cached global (traceback, getinfo, getlocal, getupvalue); strip setlocal/setmetatable/setupvalue and getmetatable (the last bypasses __metatable, a sandbox hole). - Add the traceback module (runtime/lua/modules/traceback) with format(level, opts) and frames(level, opts): structured frames carrying locals and upvalues, with cycle detection and depth/locals/upvalues/max_value_len/ max_table_depth options. Frames that panic under post-recover conditions are skipped instead of aborting the trace. - Register traceback as a core ambient module (require-able + global). - Bump github.com/wippyai/go-lua to pick up xpcall catching errors under direct PCall/DoString and inspect.GetStackFrame now capturing upvalues, both prerequisites for throw-site capture from an xpcall handler.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python-style stack-trace + locals capture for Wippy Lua scripts, on demand.
Why
Lua scripts had no way to capture a stack trace with local variables — only a bare
debug.tracebackstring with no locals, and even that was unavailable becauseSkipOpenLibsexcluded thedebuglibrary entirely.What
debugsubset as a cached global (cached_libs.go):traceback,getinfo,getlocal,getupvalue. Stripped:setlocal,setmetatable,setupvalue, andgetmetatable(the last bypasses__metatable— a sandbox hole).tracebackmodule (runtime/lua/modules/traceback):traceback.format(level, opts)— formatted multi-line string (Pythontraceback.format_excstyle).traceback.frames(level, opts)— structured frames withlocalsandupvalues.depth,locals,upvalues,max_value_len,max_table_depth.core_modules.go) —require("traceback")and global.Usage
Dependencies
Bumps
github.com/wippyai/go-luato a pre-release commit (wippyai/go-lua#32) for two prerequisites:xpcallcatching errors under directPCall/DoString, andinspect.GetStackFramecapturing upvalues. Once wippyai/go-lua#32 merges and tags a release, the pseudo-version can be replaced with the tag.Testing
make test-runtime,make lint, gofmt, vet — green.Sample output (xpcall throw-site capture)
No visual/UI changes (runtime-only feature).