lua-users home
lua-l archive

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


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