[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How do I get two dimensional array access notation for my (matrix) userdata?
- From: "E. Wing" <ewmailing@...>
- Date: Mon, 28 Jul 2008 21:36:31 -0700
On 7/28/08, Patrick Donnelly <firstname.lastname@example.org> wrote:
> On Mon, Jul 28, 2008 at 5:15 AM, E. Wing <email@example.com> wrote:
>> I can modify the vector later and its changes will be reflected in the
>> matrix which is good. But I realized that the matrix can get released
>> by the garbage collector even though there might still be vectors that
>> have a pointer to it. So if I do this:
>> my_matrix = nil
>> print(my_vector1) -- I expect garbage or crashes
> I would be hesitant to say this is a good thing. From a C perspective
> it looks natural, but if this is to be used by a script writer (e.g.
> someone who uses tools like MatLab), this may seem very strange. In
> Matlab, they make copies of a matrix/vector when you reference it.
> There are places where you cannot simulate this entirely in Lua (e.g.
> passing the matrix to a function); but, having a vector still
> reference a matrix is odd.
You have a good point. I can see where people might think they get a
unique copy of a vector to play with. This problem came up however as
a side effect to making the simple case work:
matrix = 3
>From the original explanation I received, I needed to return a vector
that could modify the original data in the matrix, otherwise the
assignment in the above case will get lost. It wasn't my intention to
make this work:
vector = matrix
It just came into existence as a side-effect.
Assuming I want a copy behavior instead of a reference behavior, is
there a way to do this while still having the matrix = 3 case