Skip to content

Track upvalue names in prototypes (for debug.getupvalue / setupvalue) #256

Closed

Description

@davydog187

Problem

debug.getupvalue(f, n) and debug.setupvalue(f, n, v) are stubbed to return nil. Implementing them requires knowing the name of each upvalue, which the compiler currently does not store on the %Prototype{}. As a result locals.lua is fully deferred — it expects debug.getupvalue(load"a=3", 1) to return ("_ENV", ...).

Scope

  1. Extend %Lua.Compiler.Prototype{} with upvalue_names :: [String.t()]. Populate from state.functions[func_key].upvalue_descriptors in lib/lua/compiler/scope.ex (each descriptor already knows the source name).
  2. lib/lua/vm/stdlib/debug.ex:
    • debug.getupvalue({:lua_closure, proto, upvalues}, n) — return {Enum.at(proto.upvalue_names, n-1), elem(upvalues, n-1)} (with bounds-check returning nil).
    • debug.setupvalue(...) — update the upvalue cell or tuple slot, return the old name.
  3. The chunk-level prototype's first upvalue is _ENV; verify the name is recorded correctly. Suite test locals.lua:73 asserts exactly this.
  4. While here: surface upvalue names in Lua.VM.Display / stack traces for better error reporting.

Acceptance

  • debug.getupvalue(load"a=3", 1) == ("_ENV", _G).
  • locals.lua either passes or progresses to an unrelated failure. Replace its :all skip.
  • Unit tests in test/lua/vm/stdlib/debug_test.exs (new) covering name lookup, bounds, and the _ENV chunk-upvalue case.

Activity

  1. added this to the 1.0.0 milestone on May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    direction:ADirection A: suite triage to 0.5.0kind:suiteLua 5.3 official test suite work

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions