From a04d55d13e9b4bf1885b731e6eab27d2763b2ca6 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 16 Jul 2019 23:03:27 -0700 Subject: [PATCH] Fix quat indexing in vanilla Lua; --- src/api/l_vectors.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/l_vectors.c b/src/api/l_vectors.c index 2ccc59d0..d8916e90 100644 --- a/src/api/l_vectors.c +++ b/src/api/l_vectors.c @@ -1366,7 +1366,8 @@ static int l_lovrQuat__newindex(lua_State* L) { const char* key = lua_tolstring(L, 2, &length); float x = luax_checkfloat(L, 3); if (length == 1 && key[0] >= 'w' && key[0] <= 'z') { - q[(key[0] - 'x') % 4] = x; + int index = key[0] == 'w' ? 3 : key[0] - 'x'; + q[index] = x; return 0; } } @@ -1400,7 +1401,8 @@ static int l_lovrQuat__index(lua_State* L) { size_t length; const char* key = lua_tolstring(L, 2, &length); if (length == 1 && key[0] >= 'w' && key[0] <= 'z') { - lua_pushnumber(L, q[(key[0] - 'x') % 4]); + int index = key[0] == 'w' ? 3 : key[0] - 'x'; + lua_pushnumber(L, q[index]); return 1; } }