[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The real problem with vectors and Lua (Atomic Tuples)
- From: "Dylan Cuthbert" <dylan@...>
- Date: Mon, 30 Jun 2003 15:09:13 +0900
Hi there, thanks for the input, I'll do some exploring in that direction
(the userdata metatable overriding)
> Not all vectors are three-dimensional. Should longer vectors be copied
> as well when assigned? You could do copy-on-write, but without reference
> counting this might be inefficient and as we all know, Lua doesn't use
> reference counting. Do you want Lua to be limited to 3/4D vectors?
I was thinking along the lines of copy-on-write. No the problem I'm having,
generally speaking, isn't 3d/4d related at all really, I'd like it to be as
general as possible. Although huge "tuples" would incur overhead, I don't
see these "tuples" being expanded upon or modified (like tables are) after
they've been created, so hash-collating is possible for vectors with the
same values. (as it is for strings and numbers)
Something like (this is totally off the top of my head.. don't rip me to
shreds)
position = << 10, 20, 30 >> -- create a "tuple"
position.another_value = 10 -- ERROR.. position isn't a table and is a
"const" in effect
position<<x>> = 30 -- creates a new "const" vector with x as 30 and
the rest from position
position<<x,y>> = 50, 70 -- writes to x, y, and takes z from position,
creating a new vector
The main thing to spot, is that apart from the << >> syntax (which I
spuriously made up) position is acting exactly like a regular number or
string containing variable. The x, y, z are simply "syntactic sugar"; named
indexing for 0, 1, 2 and isn't totally necessary.
Regards
---------------------------------
Q-Games, Dylan Cuthbert.
http://www.q-games.com
"Tuomo Valkonen" <tuomov@modeemi.cs.tut.fi> wrote in message
20030630053405.GA9856@fanta.modeemi.cs.tut.fi">news:20030630053405.GA9856@fanta.modeemi.cs.tut.fi...
> On Mon, Jun 30, 2003 at 11:02:04AM +0900, Dylan Cuthbert wrote:
> > 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.
>
> So you just create a vector userdata (lua_newuserdata) that has no
> __newindex metamethod and now your vectors are immutable objects like
> strings (unless you provide other methods to modify them). If you
> want to change a coordinate, do something like
>
> foo = change_x(foo, 10).
>
> Of course this copying will generate some garbage, but IIRC you mentioned
> that most of the time you will be changing whole vectors anyway.
>
> > There is *never* any reason to want them to be the same object.
>
> Not all vectors are three-dimensional. Should longer vectors be copied
> as well when assigned? You could do copy-on-write, but without reference
> counting this might be inefficient and as we all know, Lua doesn't use
> reference counting. Do you want Lua to be limited to 3/4D vectors?
>
> --
> Tuomo
>