[Date Prev][Date Next][Thread Prev][Thread Next]
- 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 <email@example.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
> both work?
I don't think it is possible to get the syntax you want with standard
Lua. "mymatrix = x" cannot be easily handled differently to
"local _temp = mymatrix; _temp = 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: