[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How do I get two dimensional array access notation for my (matrix) userdata?
- From: "Duncan Cross" <duncan.cross@...>
- Date: Sun, 27 Jul 2008 10:47:11 +0100
On Sun, Jul 27, 2008 at 8:10 AM, E. Wing <ewmailing@gmail.com> wrote:
> Is this possible to do? Can somebody explain how I would modify my C
> code (which is based on PiL) to do this?
>
> And can this peacefully coexist with what I already have, in
> particular, the array index style? So can I have
> my_matrix[1][2]
> and
> my_matrix[2]
> both work?
I don't think it is possible to get the syntax you want with standard
Lua. "mymatrix[1][2] = x" cannot be easily handled differently to
"local _temp = mymatrix[1]; _temp[2] = x" which obviously isn't what
you want as the value of _temp will be a number.
The closest thing I can think of to suggest is to add a new __call
metamethod to the matrix metatable which either takes two parameters
to retrieve the value at those indices:
x = my_matrix(1,2)
...or three parameters to set the value at those indices:
mymatrix(1,2,x)