From 96ac7687f009037e764a6beb32d7cbe4a8519aed Mon Sep 17 00:00:00 2001 From: brinkqiang Date: Sun, 2 Dec 2018 01:11:08 +0800 Subject: [PATCH] add --- include/dmlua_engine.h | 206 ++++++++++++++++++++++++++++++++++++++- include/dmlua_opt.h | 215 ----------------------------------------- 2 files changed, 205 insertions(+), 216 deletions(-) delete mode 100644 include/dmlua_opt.h diff --git a/include/dmlua_engine.h b/include/dmlua_engine.h index 37c8894..172f3f8 100644 --- a/include/dmlua_engine.h +++ b/include/dmlua_engine.h @@ -38,7 +38,6 @@ #include "dmtypes.h" #include "dmparser.h" #include "dmsingleton.h" -#include "dmlua_opt.h" #ifdef __APPLE__ #include @@ -302,6 +301,211 @@ class CLuaFunctionExtract { // tolua_begin // tolua_end +template +struct LuaReader +{ + static inline T Read(lua_State* L, int index) + { + if (CluaTypeid::Instance().get_name()) { + return (T)tolua_tousertype(L, index, CluaTypeid::Instance().get_name()); + } + else { + return (T)tolua_touserdata(L, index, NULL); + } + } +}; + +template +struct LuaReader +{ + static inline T* Read(lua_State* L, int index) + { + if (CluaTypeid::Instance().get_name()) { + return (T*)tolua_tousertype(L, index, CluaTypeid::Instance().get_name()); + } + else { + return (T*)tolua_touserdata(L, index, NULL); + } + } +}; + +template +struct LuaReader +{ + static inline T& Read(lua_State* L, int index) + { + if (CluaTypeid::Instance().get_name()) { + return *(T*)tolua_tousertype(L, index, CluaTypeid::Instance().get_name()); + } + else { + return *(T*)tolua_touserdata(L, index, NULL); + } + } +}; + +template <> +struct LuaReader +{ + static inline void Read(lua_State* L, int index) + { + + } +}; + +template <> +struct LuaReader +{ + static inline void* Read(lua_State* L, int index) + { + return tolua_touserdata(L, index, NULL); + } +}; + +template <> +struct LuaReader +{ + static inline char Read(lua_State* L, int index) + { + return (char)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline unsigned char Read(lua_State* L, int index) + { + return (unsigned char)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline short Read(lua_State* L, int index) + { + return (short)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline unsigned short Read(lua_State* L, int index) + { + return (unsigned short)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline int Read(lua_State* L, int index) + { + return (int)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline unsigned int Read(lua_State* L, int index) + { + return (unsigned int)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline long Read(lua_State* L, int index) + { + return (long)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline unsigned long Read(lua_State* L, int index) + { + return (unsigned long)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline long long Read(lua_State* L, int index) + { + return (long long)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline unsigned long long Read(lua_State* L, int index) + { + return (unsigned long long)tolua_tointeger(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline float Read(lua_State* L, int index) + { + return (float)tolua_tonumber(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline double Read(lua_State* L, int index) + { + return (double)tolua_tonumber(L, index, 0); + } +}; + +template <> +struct LuaReader +{ + static inline const char* Read(lua_State* L, int index) + { + return tolua_tostring(L, index, ""); + } +}; + +template <> +struct LuaReader +{ + static inline char* Read(lua_State* L, int index) + { + return const_cast(tolua_tostring(L, index, "")); + } +}; + +template <> +struct LuaReader +{ + static inline bool Read(lua_State* L, int index) + { + if (lua_isnil(L, index)) { return false; } + if (lua_isboolean(L, index)) { + return tolua_toboolean(L, index, 0) != 0; + } + else { + return tolua_tonumber(L, index, 0) != 0; + } + } +}; + +template +static inline T LuaPop(lua_State* L) { T ret = LuaReader::Read(L, -1); lua_pop(L, 1); return ret; } + +static inline void LuaPop(lua_State* L) { lua_pop(L, 1); } class CDMLuaEngine : public CDMSafeSingleton { friend class CDMSafeSingleton; diff --git a/include/dmlua_opt.h b/include/dmlua_opt.h deleted file mode 100644 index 8105725..0000000 --- a/include/dmlua_opt.h +++ /dev/null @@ -1,215 +0,0 @@ - -#ifndef __DMLUA_OPT_H_INCLUDE__ -#define __DMLUA_OPT_H_INCLUDE__ - -#include -#include "dmlua.h" - -template -struct LuaReader -{ - static inline T Read(lua_State* L, int index) - { - if (CluaTypeid::Instance().get_name()) { - return (T)tolua_tousertype(L, index, CluaTypeid::Instance().get_name()); - } - else { - return (T)tolua_touserdata(L, index, NULL); - } - } -}; - -template -struct LuaReader -{ - static inline T* Read(lua_State* L, int index) - { - if (CluaTypeid::Instance().get_name()) { - return (T*)tolua_tousertype(L, index, CluaTypeid::Instance().get_name()); - } - else { - return (T*)tolua_touserdata(L, index, NULL); - } - } -}; - -template -struct LuaReader -{ - static inline T& Read(lua_State* L, int index) - { - if (CluaTypeid::Instance().get_name()) { - return *(T*)tolua_tousertype(L, index, CluaTypeid::Instance().get_name()); - } - else { - return *(T*)tolua_touserdata(L, index, NULL); - } - } -}; - -template <> -struct LuaReader -{ - static inline void Read(lua_State* L, int index) - { - - } -}; - -template <> -struct LuaReader -{ - static inline void* Read(lua_State* L, int index) - { - return tolua_touserdata(L, index, NULL); - } -}; - -template <> -struct LuaReader -{ - static inline char Read(lua_State* L, int index) - { - return (char)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline unsigned char Read(lua_State* L, int index) - { - return (unsigned char)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline short Read(lua_State* L, int index) - { - return (short)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline unsigned short Read(lua_State* L, int index) - { - return (unsigned short)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline int Read(lua_State* L, int index) - { - return (int)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline unsigned int Read(lua_State* L, int index) - { - return (unsigned int)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline long Read(lua_State* L, int index) - { - return (long)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline unsigned long Read(lua_State* L, int index) - { - return (unsigned long)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline long long Read(lua_State* L, int index) - { - return (long long)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline unsigned long long Read(lua_State* L, int index) - { - return (unsigned long long)tolua_tointeger(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline float Read(lua_State* L, int index) - { - return (float)tolua_tonumber(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline double Read(lua_State* L, int index) - { - return (double)tolua_tonumber(L, index, 0); - } -}; - -template <> -struct LuaReader -{ - static inline const char* Read(lua_State* L, int index) - { - return tolua_tostring(L, index, ""); - } -}; - -template <> -struct LuaReader -{ - static inline char* Read(lua_State* L, int index) - { - return const_cast(tolua_tostring(L, index, "")); - } -}; - -template <> -struct LuaReader -{ - static inline bool Read(lua_State* L, int index) - { - if (lua_isnil(L, index)) { return false; } - if (lua_isboolean(L, index)) { - return tolua_toboolean(L, index, 0) != 0; - } - else { - return tolua_tonumber(L, index, 0) != 0; - } - } -}; - -template -static inline T LuaPop(lua_State* L) { T ret = LuaReader::Read(L, -1); lua_pop(L, 1); return ret; } - -static inline void LuaPop(lua_State* L) { lua_pop(L, 1); } - -#endif // __DMLUA_OPT_H_INCLUDE__ -