lua-users home
lua-l archive

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


> From: "Curt Carpenter" <curtc@microsoft.com>
>
> What's the more "Lua" way to generically create a closure for a given
> function and its arbitrary arg list than the following:

    How about sticking it into a table.

---

    local the_closures = {
        [0] = function(...) return func() end,
        [1] = function(...) return func( arg[1] ) end,
        etc...
    }

function closure(func,...)

    local my_closure = the_closures[ arg.n ] or function() assert( false )
end
    return my_closure( args )

end

---

    Tom