diff --git a/include/dmlua_opt.h b/include/dmlua_opt.h index 60a1ffe..bd0e487 100644 --- a/include/dmlua_opt.h +++ b/include/dmlua_opt.h @@ -5,66 +5,16 @@ #include #include "dmlua.h" -struct lua_nil {}; -// 如果C为true则是A类型,false是B类型 -template struct if_ {}; -template struct if_ { typedef A type; }; -template struct if_ { typedef B type; }; - -// 判断是否指针 -template -struct is_ptr { static const bool value = false; }; -template -struct is_ptr { static const bool value = true; }; - -// 判断是否是引用 -template -struct is_ref { static const bool value = false; }; -template -struct is_ref { static const bool value = true; }; - -// 获取基本类型 指针以及引用 -template -struct base_type { typedef T type; }; -template -struct base_type { typedef T type; }; -template -struct base_type { typedef T type; }; - -// 输入参数转成T类型 -template -struct void2val { static T invoke(void* input) { return *(T*)input; } }; -// 输入参数转成T类型指针 -template -struct void2ptr { static T* invoke(void* input) { return (T*)input; } }; -// 输入参数转成T类型引用 -template -struct void2ref { static T& invoke(void* input) { return *(T*)input; } }; - -// 将输入参数ptr转换成T T* 或者T& -template -struct void2type { - static T invoke(void* ptr) { - return if_::value, - void2ptr::type>, - typename if_::value, - void2ref::type>, - void2val::type> - >::type - >::type::invoke(ptr); - } -}; - template struct LuaReader { static inline T Read(lua_State* L, int index) { if (CluaTypeid::Instance().get_name()) { - return void2type::invoke(tolua_tousertype(L, index, nullptr)); + return (T)tolua_tousertype(L, index, CluaTypeid::Instance().get_name()); } else { - return void2type::invoke(tolua_touserdata(L, index, nullptr)); + return (T)tolua_touserdata(L, index, NULL); } } };