Bug with `debug.getlocal` (mismatch compared to official Lua 5.1)
You must post issues only here. Questions, ideas must be posted in discussions.
Please answer the following before submitting your issue:
- What version of GopherLua are you using? : latest version (commit 6581935)
- What version of Go are you using? : Go 1.19
- What operating system and processor architecture are you using? : linux/amd64
- What did you do? :
I ran this program:
if true then
local not_visible = "true"
else
local not_visible = "false"
end
function get_locals(func)
local n = 1
local locals = {}
while true do
local lname, lvalue = debug.getlocal(2, n)
if lname == nil then break end
locals[lname] = lvalue
n = n + 1
end
return locals
end
local should_exist = "foo"
local vars = get_locals(1)
print("should not exist:", vars["not_visible"])
print("should exist:", vars["should_exist"])
- What did you expect to see? :
The get_locals function should return a table that does not have not_visible as a key, and does have should_exist as a key. I would expect it to print:
should not exist: nil
should exist: foo
That is what the official Lua5.1 interpreter prints when it runs this file.
- What did you see instead? :
Instead I see
should not exist: function: 0xc0000fb080
should exist: nil
For some reason not_visible exists and is a function, and should_exist is nil.
For this case, glua does not produce the same output as lua5.1, which is a bug.
I have made an initial fix on my fork at: https://github.com/zyedidia/gopher-lua. I may clean it up and open a PR at some point.