|
Dylan wrote:
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
I haven't been following this thread too carefully, but userdata is what you want. It seems like you are on that path anyway.
Don't be afraid to let these vectors exist as either your native aligned format or a Lua array depending on what is convenient. You just need to be able to translate between the two. So I'd rewrite what you have above as:
position = Vector { 10, 20, 30 } -- Vector_XYZ is assumed position.another_value = 10 -- ERROR position:Set(Vector_X { 30 }) -- you might also support Vector_X(30) -- for efficiency position:Set(Vector_XY { 50, 70 }) -- other stuff lua_array = position.ToArray() lua_array[0] = 25.5 -- assuming you break Lua convention and -- start your array at 0 :-( position_b = Vector(lua_array) position_c = position * position_b -- your efficient native operation point = Vector_XY(position_c) -- extract XY as vector z = Vector_Z(position_c):ToNumber() -- extract Z as Lua number z = position_c:ToArray()[2] -- same thing z = position_c:GetScalarZ() -- same thing point_b = Vector(point) -- copyIf you haven't seen it, "Vector { 1, 2, 3 }" is table constructor syntax, equivalent to Vector({1, 2, 3}).
This isn't too far off from your C++ vector template stuff... -John -- http:// if l .o /