[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: There's gotta be a more "Lua" way to do this
- From: "Curt Carpenter" <curtc@...>
- Date: Wed, 2 Jul 2003 16:16:43 -0700
What's the more "Lua" way to generically create a closure for a given
function and its arbitrary arg list than the following:
function closure(func,...)
if arg.n == 0 then
return function() return func() end
elseif arg.n == 1 then
return function() return func(arg[1]) end
elseif arg.n == 2 then
return function() return func(arg[1],arg[2]) end
elseif arg.n == 3 then
return function() return func(arg[1],arg[2],arg[3]) end
elseif arg.n == 4 then
return function() return func(arg[1],arg[2],arg[3],arg[4]) end
elseif arg.n == 5 then
return function() return
func(arg[1],arg[2],arg[3],arg[4],arg[5]) end
else
assert(false)
end
end
Thanks,
Curt