Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with debug.getlocal (mismatch compared to official Lua 5.1) #413

Open
zyedidia opened this issue Oct 31, 2022 · 1 comment
Open

Bug with debug.getlocal (mismatch compared to official Lua 5.1) #413

zyedidia opened this issue Oct 31, 2022 · 1 comment

Comments

@zyedidia
Copy link

You must post issues only here. Questions, ideas must be posted in discussions.

Please answer the following before submitting your issue:

  1. What version of GopherLua are you using? : latest version (commit 6581935)
  2. What version of Go are you using? : Go 1.19
  3. What operating system and processor architecture are you using? : linux/amd64
  4. 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"])
  1. 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.

  1. 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.

@zyedidia
Copy link
Author

zyedidia commented Nov 1, 2022

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.

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

No branches or pull requests

1 participant