From 58cd3b411632713280396aa1af099f1878c64b78 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 29 Jan 2021 00:58:50 +0100 Subject: [PATCH] Add to string conversion for glm types in lua --- assets/lua/cameracontroller.lua | 2 ++ inferno/src/inferno/component/transformcomponent.cpp | 5 +++++ inferno/src/inferno/component/transformcomponent.h | 1 + inferno/src/inferno/script/registration.cpp | 11 ++++++----- inferno/src/inferno/script/registration.h | 10 ++++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/assets/lua/cameracontroller.lua b/assets/lua/cameracontroller.lua index 7ca1555..5506a7b 100644 --- a/assets/lua/cameracontroller.lua +++ b/assets/lua/cameracontroller.lua @@ -18,6 +18,7 @@ LuaScript = { end, update = function(self, deltaTime) + self.camera = getCameraComponent() if self.camera.type == CameraType.Orthographic then @@ -25,6 +26,7 @@ LuaScript = { elseif self.camera.type == CameraType.Perspective then LuaScript:updatePerspective(deltaTime) end + end, updateOrthographic = function(self, deltaTime) diff --git a/inferno/src/inferno/component/transformcomponent.cpp b/inferno/src/inferno/component/transformcomponent.cpp index 00da5ed..4e5edd5 100644 --- a/inferno/src/inferno/component/transformcomponent.cpp +++ b/inferno/src/inferno/component/transformcomponent.cpp @@ -2,6 +2,11 @@ namespace Inferno { + const LogStream& operator<<(const LogStream& stream, const glm::vec2& value) + { + return stream << "{ " << value.x << ", " << value.y << " }"; + } + const LogStream& operator<<(const LogStream& stream, const glm::vec3& value) { return stream << "{ " << value.x << ", " << value.y << ", " << value.z << " }"; diff --git a/inferno/src/inferno/component/transformcomponent.h b/inferno/src/inferno/component/transformcomponent.h index 1c76128..c5a4e97 100644 --- a/inferno/src/inferno/component/transformcomponent.h +++ b/inferno/src/inferno/component/transformcomponent.h @@ -17,6 +17,7 @@ namespace Inferno { // ----------------------------------------- + const LogStream& operator<<(const LogStream& stream, const glm::vec2& value); const LogStream& operator<<(const LogStream& stream, const glm::vec3& value); const LogStream& operator<<(const LogStream& stream, const glm::vec4& value); const LogStream& operator<<(const LogStream& stream, const glm::mat4& value); diff --git a/inferno/src/inferno/script/registration.cpp b/inferno/src/inferno/script/registration.cpp index a85fc87..8f87980 100644 --- a/inferno/src/inferno/script/registration.cpp +++ b/inferno/src/inferno/script/registration.cpp @@ -33,7 +33,8 @@ namespace Inferno { "__add", addition(), "__sub", subtraction(), "__mul", multiplication(), - "__div", division() + "__div", division(), + "__tostring", string ); auto vec3 = glm.new_usertype( @@ -45,8 +46,8 @@ namespace Inferno { "__add", addition(), "__sub", subtraction(), "__mul", multiplication(), - "__div", division() - // "__tostring", [](glm::vec3 self) { return self.x; } // Template!!! convert via logstream + "__div", division(), + "__tostring", string ); auto vec4 = glm.new_usertype( @@ -58,7 +59,8 @@ namespace Inferno { "__add", addition(), "__sub", subtraction(), "__mul", multiplication(), - "__div", division() + "__div", division(), + "__tostring", string ); glm.set_function("radians", sol::overload( @@ -110,7 +112,6 @@ namespace Inferno { void Registration::input(sol::state_view& state) { state.set_function("keyCode", &keyCode); - // state["keyCode"] = &KeyCode; auto input = state.new_usertype("Input", sol::no_constructor); input["isKeyPressed"] = &Input::isKeyPressed; diff --git a/inferno/src/inferno/script/registration.h b/inferno/src/inferno/script/registration.h index f5463e8..743bbc1 100644 --- a/inferno/src/inferno/script/registration.h +++ b/inferno/src/inferno/script/registration.h @@ -4,6 +4,8 @@ #include "sol/overload.hpp" // sol::overload #include "sol/state_view.hpp" // sol::state_view +#include "inferno/io/log.h" + namespace Inferno { class Registration final { @@ -54,6 +56,14 @@ namespace Inferno { [](const V& lhs, const T& rhs) { return lhs / rhs; } ); } + + template + static std::string string(const T& t) + { + std::string result; + str(&result) << t; + return result; + } }; }