lua-users home
lua-l archive

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


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)