• Subject: Re: The real problem with vectors and Lua
• From: "Dylan Cuthbert" <dylan@...>
• Date: Mon, 30 Jun 2003 11:02:04 +0900

```<RLake@oxfam.org.pe> wrote in message
OF6EBFA4E4.2822513F-ON05256D52.005B0EE5@oxfam.org.uk">news:OF6EBFA4E4.2822513F-ON05256D52.005B0EE5@oxfam.org.uk...
>
> You cannot change a "component" of an atomic object. So if vectors were,
> like Python tuples, immutable sequences, you wouldn't be able to say:
>
>   position.x = 10
>
> either. You would have to say something like:
>
>   position = replace(position, "x", 10)
>
> but I have a hunch that you don't actually want to do that.
>
> Would you settle for this?
>
>   position = position ^ {x = 10}

I don't mind position:set_x( 10 ), but this is getting away from my point,
my problem is the fact that these vectors are classed as *tables* in Lua.  I
need them classed as atomic objects like strings.  There is another mail in
this thread from Adam D Moss and he refers to "all hell breaking loose",
that is a serious problem for a language that is being bandied about as a
scripting environment.

> > and no.. writing vector = vector.copy( position) or some such is *not*
> an
> > option. ;-)
>
> Why not? You don't want to say what you mean? :) What if you *meant* for
> them to be the same object?

There is *never* any reason to want them to be the same object.  Vectors
need to be treated in the same way as "numbers" and strings.  They are
mathematical atomic types and should be treated as such.  (in games at
least)

If I wanted to pass a vector into a function as a reference (for it to be
altered by the function) I would encapsulate it in a table as I would a
number or a string.  Although the best way is to simply return the changed
value.  position = dot_product( position ) for example.

If I could disable the default taking of a reference with an error I would
be happier - ie.

vector = position -- generates some kind of error
vector = Vector( position )  -- takes a copy and is safe

But of course, table copying anything with vectors in would be broken.
(unless I hack together my own table copy that checks each entry :-( )

Regards

---------------------------------
Q-Games, Dylan Cuthbert.
http://www.q-games.com

```

• References: