lua-users home
lua-l archive

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

On 4/18/2016 10:11 AM, Ulrich Schmidt wrote:
I know. The background of my question was: I like to hide functions inside functions hided inside functions.
This helps me to make excessive use of code folding in ZBS and keeps things as local as possible.

That's what do-end blocks are for.

But i was not sure, it slows down something.

Starting in Lua 5.2, a closure that does not have any upvalues will be cached and reused.

    function noclosure(x)
        a = x
        return function()
            return a

    function withclosure(x)
        local a = x
        return function()
            return a

    print(noclosure(1) == noclosure(2))
    -- true
    print(withclosure(1) == withclosure(2))
    -- false

-- tom