lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


When f is called, a new local is set which means the function needs a new way to get that local. With g(), the local is at the same address, so it doesn't need to recompile. 

On Thu, Oct 6, 2016, 8:16 AM Rodrigo Azevedo <rodrigoams@gmail.com> wrote:
Given the code:

f = function ()
        local o = 10
        return
                function(x) return x+o end
end

local o = 10
g = function ()
        return
                function(x) return x+o end
end

print(f(),f(),g(),g())

It prints:

function: 0x2196ff0    function: 0x21965f0    function: 0x2196da0    function: 0x2196da0

The problem:  Why f() returns different functions while g() does not?



--
Rodrigo Azevedo Moreira da Silva
--