Allow push to work with types that inherit from reference

This commit is contained in:
HFCPC 2013-11-25 16:44:05 -05:00
parent c8c82ee56b
commit f2d72f7bb2

View File

@ -84,6 +84,18 @@ inline void push_arithmetic(lua_State* L, T x, std::false_type) {
// T is an floating point type // T is an floating point type
lua_pushnumber(L, x); lua_pushnumber(L, x);
} }
template<typename T>
inline void push_helper(lua_State* L, T& x, std::true_type) {
// T is a reference type
x.push();
}
template<typename T>
inline void push_helper(lua_State* L, T& x, std::false_type) {
// T is a reference type
push_arithmetic<T>(L, x, std::is_integral<T>{});
}
} // detail } // detail
template<typename T> template<typename T>
@ -116,8 +128,8 @@ inline const char* pop<const char*>(lua_State* L) {
} }
template<typename T> template<typename T>
inline void push(lua_State* L, T arithmetic) { inline void push(lua_State* L, T& t) {
detail::push_arithmetic(L, arithmetic, std::is_integral<T>{}); detail::push_helper(L, t, std::is_base_of<reference, T>{});
} }
inline void push(lua_State* L, bool boolean) { inline void push(lua_State* L, bool boolean) {