[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: sunday afternoon whishlist
- From: "Juris Kalnins" <juris@...>
- Date: Tue, 11 May 2010 08:51:20 +0300
On Mon, 10 May 2010 19:51:05 +0300, HyperHacker <hyperhacker@gmail.com>
wrote:
An obvious one I see is what happens when you do this?
t = {}
t[1,2] = 42
t[1,2] = 27
On line 2 it's going to pass two parameters to __index, but on line
three, unless a __usedindex or some such method is added (which I
highly support and have already patched into my own copy), where do
the multiple parameters go?
No, on line 2 it will error out, because there is no metatable, and
the default newindex(t, 1, 2, 42) would forward to newindex(t[1], 2, 42).
Same for the line three. If there _was_ a metatable for t, it's
__newindex would get called with all the parameters
On Mon, 10 May 2010 10:13:43 +0300, Eike Decker <zet23t@googlemail.com>
wrote:
Hm. Difficult. To the called metatable function, the input of x[y,z]
= v would look pretty similar to x[y,z,v] = nil. And if you'd pass
more arguments than expected by your index function, you'd get some
pretty "interesting" results ... so more or less, your index function
would be required to accept (...) arguments and then expect the last
value as the value to be assigned.
Right. The proposed calling convention is pretty random. 'x[] = 5' would
delete element with index 5 if the method is not "multi-aware", etc.
(But anyway, not being able to cheaply check number of arguments
passed to the function is .. "not convenient". Something
like "#..." would be really good to have)
The big idea actually was to have a meta interface that supports
multiple keys and multiple values; for lookup, insertion and for iteration.
Especially for iteration. But it doesn't seem possible with the Lua calling
convention. But multiple keys, single value might be possible.