[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.1+ and variable-argument tables
- From: Mark Hamburg <mhamburg@...>
- Date: Fri, 20 Aug 2004 16:12:26 -0700
I rather like that as a way of dealing with the magic name "arg".
It also simplifies some other things like writing cleanup wrappers using
pcall. For example one can then have:
function Mutex:do( func )
-- Execute func with locked mutex. Returns results of
-- executing func.
self:lock()
local success, result, others[] = pcall( func )
self:unlock()
if not success then error( result ) end
return result, others[]
end
Too bad it creates extra heap allocations.
This snippet also points to a moderately interesting idiom with respect to
pcall that isn't entirely easy or at least efficient to implement today.
Mark
on 8/20/04 2:43 PM, Edgar Toernig at froese@gmx.de wrote:
> Hehe, iirc I once suggested:
>
> a, b, c[] = f() -- pack into c
>
> function foo(a, b, c[]) -- define vararg function
>
> foo(1, 2, c[]) -- unpack c