[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: There's gotta be a more "Lua" way to do this
- From: "Tom Spilman" <tom@...>
- Date: Wed, 2 Jul 2003 21:20:31 -0500
> 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