[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.1+ and variable-argument tables
- From: Edgar Toernig <froese@...>
- Date: Sat, 21 Aug 2004 04:42:47 +0200
Mark Hamburg wrote:
>
> I rather like that as a way of dealing with the magic name "arg".
:-) From Sol's changelog:
| sol 0.25 Tue, 14 Nov 2000 18:54:30 +0100 by root
| Parent-Version: 0.24
| Version-Log: changed vararg syntax: '...' -> 'name[]'
|
| sol 0.24 Tue, 14 Nov 2000 17:38:16 +0100 by root
| Parent-Version: 0.23
| Version-Log: removed implicit 'self' parameter in function definitions
> Too bad it creates extra heap allocations.
Yeah. That was the reason for:
| sol 0.116 Thu, 24 Apr 2003 04:27:29 +0200 by froese
| Parent-Version: 0.115
| Version-Log: new varargs - '...' as multi-value
> 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.
With the new varargs you can implement it without heap allocations:
local function do2(self, success, ...)
self:unlock()
if not success then error(..., 2) end
return ...
end
function Mutex:do(...)
self:lock()
do2(self, pcall(...))
end
Not pretty but reasonable fast.
Ciao, ET.