add new mat4.tostring overload

This commit is contained in:
MihailRis 2024-06-18 00:18:21 +03:00
parent 88b21262a3
commit 097d4e3c6b
2 changed files with 18 additions and 3 deletions

View File

@ -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());

View File

@ -393,6 +393,7 @@ namespace lua {
pop(L);
}
}
pop(L);
return matrix;
}