From efb4532536dd85c1edde19a6fc40e2ff19f807d6 Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 00:55:04 +0500 Subject: [PATCH 1/3] add mul* functions to quats & fix to_string --- src/logic/scripting/lua/libs/libquat.cpp | 40 ++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/logic/scripting/lua/libs/libquat.cpp b/src/logic/scripting/lua/libs/libquat.cpp index 53757cb36..5002e9bb3 100644 --- a/src/logic/scripting/lua/libs/libquat.cpp +++ b/src/logic/scripting/lua/libs/libquat.cpp @@ -1,3 +1,5 @@ +#include +#include #include "api_lua.hpp" #define GLM_ENABLE_EXPERIMENTAL @@ -31,14 +33,14 @@ static int l_tostring(lua::State* L) { lua::check_argc(L, 1); auto quat = lua::toquat(L, 1); + float components[4] = {quat.w, quat.x, quat.y, quat.z}; std::stringstream ss; - ss << "quat" - << "{"; + ss << "quat" << "{"; for (int i = 0; i < 4; i++) { if (i > 0) { ss << ", "; } - ss << quat[i]; + ss << components[i]; } ss << "}"; return lua::pushstring(L, ss.str()); @@ -52,10 +54,42 @@ static int l_from_euler(lua::State *L) { return lua::pushquat(L, glm::quat(euler)); } +static int l_mul(lua::State* L) { + uint argc = lua::check_argc(L, 2, 3); + glm::quat a = lua::toquat(L, 1); + glm::quat b = lua::toquat(L, 2); + + glm::quat result = a * b; + + if (argc == 3) { + lua::setquat(L, 3, result); + return 0; + } + + return lua::pushquat(L, result); +} + +static int l_mul_vec3(lua::State* L) { + uint argc = lua::check_argc(L, 2, 3); + glm::quat q = lua::toquat(L, 1); + glm::vec3 v = lua::tovec3(L, 2); + + glm::vec3 result = q * v; + + if (argc == 3) { + lua::setvec(L, 3, result); + return 0; + } + + return lua::pushvec3(L, result); +} + const luaL_Reg quatlib[] = { {"from_mat4", lua::wrap}, {"from_euler", lua::wrap}, {"slerp", lua::wrap}, {"tostring", lua::wrap}, + {"mul", lua::wrap}, + {"mul_vec3", lua::wrap}, {nullptr, nullptr} }; From ae5c1a4533ae10b026761d6609617b25719c7003 Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 01:08:32 +0500 Subject: [PATCH 2/3] move GLM_EXPERIMENTAL to the top --- src/logic/scripting/lua/libs/libquat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/scripting/lua/libs/libquat.cpp b/src/logic/scripting/lua/libs/libquat.cpp index 5002e9bb3..d062f40a4 100644 --- a/src/logic/scripting/lua/libs/libquat.cpp +++ b/src/logic/scripting/lua/libs/libquat.cpp @@ -1,8 +1,8 @@ +#define GLM_ENABLE_EXPERIMENTAL #include #include #include "api_lua.hpp" -#define GLM_ENABLE_EXPERIMENTAL #include #include #include From 516b4064768db430eb3e91665367ed9f096fce45 Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 01:18:39 +0500 Subject: [PATCH 3/3] fix stringstream usage --- src/logic/scripting/lua/libs/libquat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/scripting/lua/libs/libquat.cpp b/src/logic/scripting/lua/libs/libquat.cpp index d062f40a4..a3fe62149 100644 --- a/src/logic/scripting/lua/libs/libquat.cpp +++ b/src/logic/scripting/lua/libs/libquat.cpp @@ -35,7 +35,7 @@ static int l_tostring(lua::State* L) { float components[4] = {quat.w, quat.x, quat.y, quat.z}; std::stringstream ss; - ss << "quat" << "{"; + ss << "quat {"; for (int i = 0; i < 4; i++) { if (i > 0) { ss << ", ";