Skip to content

Issue #547 : debug.getinfo reports source and short_src as Lua 5.1 - #550

Open
eldologuzzo wants to merge 1 commit into
yuin:masterfrom
eldologuzzo:fix-getinfo-source
Open

eldologuzzo wants to merge 1 commit into
yuin:masterfrom
eldologuzzo:fix-getinfo-source

Conversation

@eldologuzzo

Copy link
Copy Markdown

Fixes #547 .

Changes proposed in this pull request:

  • debug.getinfo reports source as Lua 5.1 does:
    • a function loaded with LoadFile (dofile, loadfile, require) gets "@" + file name;
    • a chunk loaded with an explicit name keeps it ("=name", "@name");
    • a Go function gets "=[C]".
  • New short_src field, built like luaO_chunkid: "@f.lua" gives f.lua, "=name" gives name, and anything else gives [string "first line..."].
  • FunctionProto.SourceName and error messages do not change. The chunks are marked in LoadFile with an unexported field.
  • Note: _glua-tests/db.lua asserted the previous GopherLua-specific source == "db.lua". It now asserts "@db.lua" and short_src == "db.lua", as in Lua 5.1, and adds cases for Go functions and named chunks. The new assertions pass on Lua 5.1.5.

🤖 Generated with Claude Code

A function loaded with LoadFile (dofile, loadfile, require) reports its
source as "@" + file name; chunks loaded with a name keep it; a Go
function reports "=[C]". short_src is added, built like luaO_chunkid.
Error messages and FunctionProto.SourceName do not change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 7, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Lua’s loadfile still bypasses the new file-origin marker and returns an unprefixed source.

1 open finding
What changed in this PR

Aligns debug.getinfo source reporting with Lua 5.1.

Changes:

  • Marks file-loaded function prototypes and prefixes their debug source with @.
  • Adds short_src generation and C-function source reporting.
  • Expands Lua debug-library tests.
File Description
state.go Updates debug source reporting.
_state.go Mirrors state debug changes.
function.go Adds the file-origin marker.
debuglib.go Adds short_src generation.
auxlib.go Marks prototypes loaded through LoadFile.
_glua-tests/​db.lua Tests Lua 5.1-compatible sources.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread auxlib.go
Comment on lines +390 to +391
if err == nil && len(path) > 0 {
markLoadedFromFile(fn.Proto)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

debug.getinfo: source has no "@" for files and short_src is missing

2 participants