]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Started lua->entityx binding
authorAndy <drumsetmonkey@gmail.com>
Mon, 26 Aug 2019 18:46:32 +0000 (14:46 -0400)
committerAndy <drumsetmonkey@gmail.com>
Mon, 26 Aug 2019 18:46:32 +0000 (14:46 -0400)
Created type converter to-and-from Lua and C

src/Script/entityx/LuaTypes.hpp [new file with mode: 0644]
src/main.cpp

diff --git a/src/Script/entityx/LuaTypes.hpp b/src/Script/entityx/LuaTypes.hpp
new file mode 100644 (file)
index 0000000..66d1f47
--- /dev/null
@@ -0,0 +1,96 @@
+#ifndef LUATYPES_HPP
+#define LUATYPES_HPP
+
+#include "lua.hpp"
+
+namespace entityx
+{
+    namespace lua
+    {
+        /*************
+        *  GENERIC  *
+        *************/
+        template<typename T>
+        inline void LuaToC(lua_State* L, T& ref);
+
+        template<typename T>
+        inline void CToLua(lua_State* L, T& ref);
+        
+        /************
+        *  DOUBLE  *
+        ************/
+        template<>
+        inline void LuaToC<double>(lua_State* L, double& ref)
+        {
+            ref = lua_tonumber(L, -1);
+        }
+
+        template<>
+        inline void CToLua(lua_State* L, double& ref)
+        {
+            lua_pushnumber(L, ref);
+        }
+
+        /***********
+        *  FLOAT  *
+        ***********/
+        template<>
+        inline void LuaToC<float>(lua_State* L, float& ref)
+        {
+            ref = static_cast<float>(lua_tonumber(L, -1));
+        }
+
+        template<>
+        inline void CToLua<float>(lua_State* L, float& ref)
+        {
+            lua_pushnumber(L, ref);
+        }
+
+        /*************
+        *  INTEGER  *
+        *************/
+        template<>
+        inline void LuaToC<int>(lua_State* L, int& ref)
+        {
+            ref = lua_tointeger(L, -1);
+        }
+
+        template<>
+        inline void CToLua<int>(lua_State* L, int& ref)
+        {
+            lua_pushnumber(L, ref);
+        }
+
+        /*************
+        *  BOOLEAN  *
+        *************/
+        template<>
+        inline void LuaToC<bool>(lua_State* L, bool& ref)
+        {
+            ref = lua_toboolean(L, -1);
+        }
+
+        template<>
+        inline void CToLua<bool>(lua_State* L, bool& ref)
+        {
+            lua_pushboolean(L, ref);
+        }
+
+        /************
+        *  STRING  *
+        ************/
+        template<>
+        inline void LuaToC<std::string>(lua_State* L, std::string& ref)
+        {
+            ref = lua_tostring(L, -1);
+        }
+
+        template<>
+        inline void CToLua<std::string>(lua_State* L, std::string& ref)
+        {
+            lua_pushstring(L, ref.c_str());
+        }
+    }
+}
+
+#endif//LUATYPES_HPP
index ef787374b921112dc58a960755c8da662d3bfdec..0fa903e0549b9bb9cf64d4a387b6d924808afff4 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include <entityx.h>
+#include <Script/entityx/LuaTypes.hpp>
 
 #include <SDL2/SDL.h>