Browse Source

Add to string conversion for glm types in lua

master
Riyyi 3 years ago
parent
commit
58cd3b4116
  1. 2
      assets/lua/cameracontroller.lua
  2. 5
      inferno/src/inferno/component/transformcomponent.cpp
  3. 1
      inferno/src/inferno/component/transformcomponent.h
  4. 11
      inferno/src/inferno/script/registration.cpp
  5. 10
      inferno/src/inferno/script/registration.h

2
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)

5
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 << " }";

1
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);

11
inferno/src/inferno/script/registration.cpp

@ -33,7 +33,8 @@ namespace Inferno {
"__add", addition<glm::vec2, float>(),
"__sub", subtraction<glm::vec2, float>(),
"__mul", multiplication<glm::vec2, float>(),
"__div", division<glm::vec2, float>()
"__div", division<glm::vec2, float>(),
"__tostring", string<glm::vec2>
);
auto vec3 = glm.new_usertype<glm::vec3>(
@ -45,8 +46,8 @@ namespace Inferno {
"__add", addition<glm::vec3, float>(),
"__sub", subtraction<glm::vec3, float>(),
"__mul", multiplication<glm::vec3, float>(),
"__div", division<glm::vec3, float>()
// "__tostring", [](glm::vec3 self) { return self.x; } // Template!!! convert via logstream
"__div", division<glm::vec3, float>(),
"__tostring", string<glm::vec3>
);
auto vec4 = glm.new_usertype<glm::vec4>(
@ -58,7 +59,8 @@ namespace Inferno {
"__add", addition<glm::vec4, float>(),
"__sub", subtraction<glm::vec4, float>(),
"__mul", multiplication<glm::vec4, float>(),
"__div", division<glm::vec4, float>()
"__div", division<glm::vec4, float>(),
"__tostring", string<glm::vec4>
);
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>("Input", sol::no_constructor);
input["isKeyPressed"] = &Input::isKeyPressed;

10
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<typename T>
static std::string string(const T& t)
{
std::string result;
str(&result) << t;
return result;
}
};
}

Loading…
Cancel
Save