[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Multiple return value in __index metamethod
- From: Rici Lake <lua@...>
- Date: Tue, 10 Jul 2007 20:57:48 -0500
On 10-Jul-07, at 7:58 PM, David Manura wrote:
Jerome Vuarand <jerome.vuarand <at> ubisoft.com> writes:
Another solution that no one else proposed is to pass several keys to
your __index metamethods. You can do that by creating a table
The following variant of that approach avoids constructing a table and
is
reasonably straightforward and efficient:
value, delta = t[i], t[-i]
(assuming the key i is a positive integer so that the domains of i
and -i are mutually exclusive).
I also like the common solution:
value, delta = t:pair(i) -- just get used to it ;)
Yet another possibility is returning a tuple, implemented
as a function.
function pair(a, b) return a, b end
t = {pair(3, 0.25), pair(4, 1.0), pair(-3, 0.8)}
for _, p in ipairs(t) do
local value, delta = p()
...
end