add vecn.sub(...), .mul(...), .div(...), .length(...), .normalize(...)

This commit is contained in:
MihailRis
2024-06-25 18:24:48 +03:00
parent 5ede84edc7
commit c7db73e25b
2 changed files with 70 additions and 13 deletions
+16
View File
@@ -328,6 +328,22 @@ namespace lua {
setglobal(L, name);
}
template<int n>
inline glm::vec<n, float> tovec(lua::State* L, int idx) {
pushvalue(L, idx);
if (!istable(L, idx) || objlen(L, idx) < n) {
throw std::runtime_error("value must be an array of "+std::to_string(n)+" numbers");
}
glm::vec<n, float> vec;
for (int i = 0; i < n; i++) {
rawgeti(L, 1);
vec[i] = tonumber(L, -1);
pop(L);
}
pop(L);
return vec;
}
inline glm::vec2 tovec2(lua::State* L, int idx) {
pushvalue(L, idx);
if (!istable(L, idx) || objlen(L, idx) < 2) {