lua-users home
lua-l archive

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

<> wrote in message">
> 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

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 :-( )


Q-Games, Dylan Cuthbert.