lua-users home
lua-l archive

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


sessile@in-gen.net wrote:
> 
> I had started down the road of creating temporary userdata(s?) as well.
> It occurred to me today that the "__index" and "__newindex" methods
> could probably be tricked into accepting "myarray[1][2]" without the
> temporaries being created by manipulating an extra field in the original
> userdata ("row" in the following example).

Very fragile!

I.e. add a line to your example and try it again:

> x = array2d.new()
> y = array2d.new()

  foo = x[1] -- this will confuse the __index method...

> for i=1,4 do
>    for j=1,4 do
>      print(string.format("%2.1f", x[i][j]))
>    end
> end

Or this:

  r1 = x[1]
  print(r1[1],r1[2],r1[3],r1[4])

Or this:

  x[1][2] = x[3][4]  -- I think, order is [1], [3], [4], [2]
                     -- which results in ... = x[1][3][4] ->error


> (Dumb C question: is there a shorter way to initialize matrix->xform?)

???

    for (i = 0; i < 4; i++)
        for (j = 0; j < 4; j++)
            matrix->xform[i][j] = 1.1 + i + 0.1*j;

Ciao, ET.