From 097d4e3c6b7c5a3cbf0dab287ddab81063b6bf76 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 18 Jun 2024 00:18:21 +0300 Subject: [PATCH] add new mat4.tostring overload --- src/logic/scripting/lua/libmat4.cpp | 20 +++++++++++++++++--- src/logic/scripting/lua/lua_util.hpp | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/logic/scripting/lua/libmat4.cpp b/src/logic/scripting/lua/libmat4.cpp index 9973b973..97e9ae82 100644 --- a/src/logic/scripting/lua/libmat4.cpp +++ b/src/logic/scripting/lua/libmat4.cpp @@ -159,13 +159,27 @@ static int l_transpose(lua::State* L) { static int l_tostring(lua::State* L) { auto matrix = lua::tomat4(L, 1); + bool multiline = lua::toboolean(L, 2); std::stringstream ss; - ss << "mat4 {\n"; + ss << "mat4 {"; + if (multiline) { + ss << "\n"; + } for (uint y = 0; y < 4; y++) { for (uint x = 0; x < 4; x++) { - ss << "\t" << matrix[y][x]; + if (multiline) { + ss << "\t" << matrix[y][x]; + } else if (x > 0) { + ss << " " << matrix[y][x]; + } else { + ss << matrix[y][x]; + } + } + if (multiline) { + ss << "\n"; + } else { + ss << "; "; } - ss << "\n"; } ss << "}"; return lua::pushstring(L, ss.str()); diff --git a/src/logic/scripting/lua/lua_util.hpp b/src/logic/scripting/lua/lua_util.hpp index c98af803..a774d283 100644 --- a/src/logic/scripting/lua/lua_util.hpp +++ b/src/logic/scripting/lua/lua_util.hpp @@ -393,6 +393,7 @@ namespace lua { pop(L); } } + pop(L); return matrix; }