[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Two indexing methods of a vector. How to ?
- From: "Charles Melice" <3d@...>
- Date: Mon, 5 Jan 2015 21:36:04 +0100
I defined (with the C API) a Vector object based on full user data.
static Vec4 *Vget(lua_State *L, int i)
{
if (luaL_checkudata(L,i,MYTYPE)==NULL) ERROR(MYTYPE);
return (Vec4*)lua_touserdata(L,i);
}
Now, I'm interested to be able to index the 'x, y, z, t' coordinates with
numeric indexes (1,2,3,4). For instance :
local v = Vec4(11,22,33,44)
print(v.y) -- 22
v:normalize()
print(v) -- Vec4(0.27, 0.53, 0.80, 1.07)
print(v[2]) -- 0.53 ???
v[2]=22.22 -- ???
print(v.y) -- 22.22
I don't see how to do that ?
Thanks,
Charles