Call Lua function by reference
snippet in lua

Call Lua function by reference

user3488

function bind(f, ...)
    local args = {...}
    return function()
        return f(unpack(args))
    end
end

foo = bind(print, "This", "is", "a", "test")
foo() --> This    is      a       test
foo() --> This    is      a       test