gopher-lua icon indicating copy to clipboard operation
gopher-lua copied to clipboard

debug.getlocal return wrong name, values when there is a for block

Open edolphin-ydf opened this issue 6 years ago • 0 comments

  • [x] GopherLua is a Lua5.1 implementation. You should be familiar with Lua programming language. Have you read Lua 5.1 reference manual carefully?
  • [x] GopherLua is a Lua5.1 implementation. In Lua, to keep it simple, it is more important to remove functionalities rather than to add functionalities unlike other languages . If you are going to introduce some new cool functionalities into the GopherLua code base and the functionalities can be implemented by existing APIs, It should be implemented as a library.

Please answer the following before submitting your issue:

  1. What version of GopherLua are you using? :
  2. What version of Go are you using? :
  3. What operating system and processor architecture are you using? :
  4. What did you do? :
  5. What did you expect to see? :
  6. What did you see instead? :

the test code is

local t = {aa = 1, bb = 2}
for k, v in pairs(t) do
    print(k, v)
end

local a = 1
local b = 2
local c = a+b
local x = 1
while true do
    local name, value = debug.getlocal(1, x)
    if not name then
        break
    end
    print(name, value)
    x = x + 1
end

and the output is

aa      1
bb      2
t       table: 0xc00006c420
(for generator) 1
(for state)     2
(for control)   3
k       5
v       function: 0xc000118700
a       1

the debug.getlocal(1, x) cannot get vars like b, c, x. hope to fix this.

edolphin-ydf avatar Nov 05 '19 05:11 edolphin-ydf