diff options
author | Andy <drumsetmonkey@gmail.com> | 2019-08-26 14:46:32 -0400 |
---|---|---|
committer | Andy <drumsetmonkey@gmail.com> | 2019-08-26 14:46:32 -0400 |
commit | c772d1b5ecffbeb9712b16a580080cb20b3bacfc (patch) | |
tree | 045338addfe4bc8f50ad547a1507de71a9acac73 /src | |
parent | b988e63410acb36f91fb4ad2b3269a8971815663 (diff) |
Started lua->entityx binding
Created type converter to-and-from Lua and C
Diffstat (limited to 'src')
-rw-r--r-- | src/Script/entityx/LuaTypes.hpp | 96 | ||||
-rw-r--r-- | src/main.cpp | 1 |
2 files changed, 97 insertions, 0 deletions
diff --git a/src/Script/entityx/LuaTypes.hpp b/src/Script/entityx/LuaTypes.hpp new file mode 100644 index 0000000..66d1f47 --- /dev/null +++ b/src/Script/entityx/LuaTypes.hpp @@ -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 diff --git a/src/main.cpp b/src/main.cpp index ef78737..0fa903e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ */ #include <entityx.h> +#include <Script/entityx/LuaTypes.hpp> #include <SDL2/SDL.h> |