Skip to content

Closures don't capture variables properly #1

@ghost

Description

Take the simple example:

function make_addr(a)
    return function(b)
        return (a + b) 
    end
end


-- should print 35
print(make_addr(15)(20))

addten = make_addr(10)
-- should print 104
print(addten(94))

Running in with the regular lua interpreter the program outputs:

35
104

however when using cargo run -- closure.lua the result is:

40
188

I think this is because each chunk does not store its own locals

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions