mirror of https://github.com/bjornbytes/lovr.git
Support table vector
This commit is contained in:
parent
4e2c0111c7
commit
117f7e3061
|
@ -42,6 +42,15 @@ static const uint32_t* swizzles[5] = {
|
|||
|
||||
// Helpers
|
||||
|
||||
inline void luax_readobjarr(lua_State* L, int index, size_t n, float* out, const char* name) {
|
||||
lovrCheck(lua_objlen(L, index) >= n, "length of %s table must >= %i", name, n);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
lua_rawgeti(L, index, i + 1);
|
||||
out[i] = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int luax_readvec2(lua_State* L, int index, vec2 v, const char* expected) {
|
||||
switch (lua_type(L, index)) {
|
||||
case LUA_TNIL:
|
||||
|
@ -52,6 +61,10 @@ int luax_readvec2(lua_State* L, int index, vec2 v, const char* expected) {
|
|||
v[0] = luax_tofloat(L, index++);
|
||||
v[1] = luax_optfloat(L, index++, v[0]);
|
||||
return index;
|
||||
case LUA_TTABLE:
|
||||
luax_readobjarr(L, index, 2, v, "vec2");
|
||||
index++;
|
||||
return index;
|
||||
default:
|
||||
vec2_init(v, luax_checkvector(L, index, V_VEC2, expected ? expected : "vec2 or number"));
|
||||
return index + 1;
|
||||
|
@ -69,6 +82,10 @@ int luax_readvec3(lua_State* L, int index, vec3 v, const char* expected) {
|
|||
v[1] = luax_optfloat(L, index++, v[0]);
|
||||
v[2] = luax_optfloat(L, index++, v[0]);
|
||||
return index;
|
||||
case LUA_TTABLE:
|
||||
luax_readobjarr(L, index, 3, v, "vec3");
|
||||
index++;
|
||||
return index;
|
||||
default:
|
||||
vec3_init(v, luax_checkvector(L, index, V_VEC3, expected ? expected : "vec3 or number"));
|
||||
return index + 1;
|
||||
|
@ -87,6 +104,10 @@ int luax_readvec4(lua_State* L, int index, vec4 v, const char* expected) {
|
|||
v[2] = luax_optfloat(L, index++, v[0]);
|
||||
v[3] = luax_optfloat(L, index++, v[0]);
|
||||
return index;
|
||||
case LUA_TTABLE:
|
||||
luax_readobjarr(L, index, 4, v, "vec4");
|
||||
index++;
|
||||
return index;
|
||||
default:
|
||||
vec4_init(v, luax_checkvector(L, index, V_VEC4, expected ? expected : "vec4 or number"));
|
||||
return index + 1;
|
||||
|
@ -112,6 +133,10 @@ int luax_readscale(lua_State* L, int index, vec3 v, int components, const char*
|
|||
}
|
||||
}
|
||||
return index;
|
||||
case LUA_TTABLE:
|
||||
luax_readobjarr(L, index, 3, v, "scale");
|
||||
index++;
|
||||
return index;
|
||||
default: {
|
||||
VectorType type;
|
||||
float* u = luax_tovector(L, index++, &type);
|
||||
|
@ -143,6 +168,12 @@ int luax_readquat(lua_State* L, int index, quat q, const char* expected) {
|
|||
az = luax_optfloat(L, index++, 0.f);
|
||||
quat_fromAngleAxis(q, angle, ax, ay, az);
|
||||
return index;
|
||||
case LUA_TTABLE:
|
||||
float v[4];
|
||||
luax_readobjarr(L, index, 4, v, "quat");
|
||||
quat_fromAngleAxis(q, v[0], v[1], v[2], v[3]);
|
||||
index++;
|
||||
return index;
|
||||
default:
|
||||
quat_init(q, luax_checkvector(L, index++, V_QUAT, expected ? expected : "quat or number"));
|
||||
return index;
|
||||
|
@ -167,6 +198,14 @@ int luax_readmat4(lua_State* L, int index, mat4 m, int scaleComponents) {
|
|||
}
|
||||
} // Fall through
|
||||
|
||||
case LUA_TTABLE:
|
||||
if (lua_type(L, index) == LUA_TTABLE && lua_objlen(L, index) >= 16) {
|
||||
luax_readobjarr(L, index, 16, m, "mat4");
|
||||
index++;
|
||||
return index;
|
||||
}
|
||||
// Fall through
|
||||
|
||||
case LUA_TNUMBER: {
|
||||
float S[3];
|
||||
float R[4];
|
||||
|
|
Loading…
Reference in New Issue