lua-users home
lua-l archive

Re: Lua 5.1+ and variable-argument tables

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Mark Hamburg wrote:
>
> I rather like that as a way of dealing with the magic name "arg".
:-) From Sol's changelog:
| sol 0.25 2000年11月14日 18:54:30 +0100 by root
| Parent-Version: 0.24
| Version-Log: changed vararg syntax: '...' -> 'name[]'
|
| sol 0.24 2000年11月14日 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 2003年4月24日 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.

AltStyle によって変換されたページ (->オリジナル) /