[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Vararg assignment thread?
- From: Petite Abeille <petite.abeille@...>
- Date: Sat, 30 Aug 2014 14:23:06 +0200
On Aug 30, 2014, at 6:03 AM, Andrew Starks <andrew.starks@trms.com> wrote:
> function o.method(self, fun, ...)
>
> success, ... = pcall(fun, ...)
> --vararg now return values of fun
> -etc.
>
> end
So, as Tim has pointed out, table.pack is what you want to make this work.
Something along these lines:
function Try( aFunction, ... )
local aResult = table.pack( pcall( aFunction, ... ) )
local ok = aResult[ 1 ]
if ok then
return table.unpack( aResult, 2, aResult.n )
end
end
If you feel adventurous, you could easily build a simple try/catch/finally mechanism out of it.
On the other hand, perhaps this was a purely rhetorical question?!?