Skip to content

Commit

Permalink
add new mat4.tostring overload
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Jun 17, 2024
1 parent 88b2126 commit 097d4e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/logic/scripting/lua/libmat4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/logic/scripting/lua/lua_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ namespace lua {
pop(L);
}
}
pop(L);
return matrix;
}

Expand Down

0 comments on commit 097d4e3

Please sign in to comment.