inline fixes

static getter/pusher
container with Unqualified
not sure how I can make containers play nice without lookup...
This commit is contained in:
PrincessNyanara 2014-06-09 02:06:51 -04:00 committed by Rapptz
parent e5bb46afda
commit 0aab55cea4
2 changed files with 16 additions and 14 deletions

View File

@ -7,7 +7,7 @@ namespace sol {
template <typename Tc, typename = void>
struct container {
typedef typename std::conditional<std::is_lvalue_reference<Tc>::value, Tc, Decay<Tc>>::type T;
typedef typename std::conditional<std::is_lvalue_reference<Tc>::value, Tc, Unqualified<Tc>>::type T;
typedef Unqualified<decltype(*(std::declval<T>().begin()))> value_type;
T cont;

View File

@ -35,12 +35,12 @@
namespace sol {
namespace detail {
template<typename T>
T* get_ptr(T& val) {
inline T* get_ptr(T& val) {
return std::addressof(val);
}
template<typename T>
T* get_ptr(T* val) {
inline T* get_ptr(T* val) {
return val;
}
} // detail
@ -102,7 +102,7 @@ struct getter<T*> {
template <>
struct getter<type> {
type get(lua_State *L, int index){
static type get(lua_State *L, int index){
return static_cast<type>(lua_type(L, index));
}
};
@ -125,14 +125,14 @@ struct getter<std::string> {
template <>
struct getter<const char*> {
const char* get(lua_State* L, int index = -1) {
static const char* get(lua_State* L, int index = -1) {
return lua_tostring(L, index);
}
};
template <>
struct getter<nil_t> {
nil_t get(lua_State* L, int index = -1) {
static nil_t get(lua_State* L, int index = -1) {
if (lua_isnil(L, index) == 0)
throw sol::error("not nil");
return nil_t{ };
@ -141,28 +141,28 @@ struct getter<nil_t> {
template <>
struct getter<userdata_t> {
userdata_t get(lua_State* L, int index = -1) {
static userdata_t get(lua_State* L, int index = -1) {
return{ lua_touserdata(L, index) };
}
};
template <>
struct getter<lightuserdata_t> {
lightuserdata_t get(lua_State* L, int index = 1) {
static lightuserdata_t get(lua_State* L, int index = 1) {
return{ lua_touserdata(L, index) };
}
};
template <>
struct getter<upvalue_t> {
upvalue_t get(lua_State* L, int index = 1) {
static upvalue_t get(lua_State* L, int index = 1) {
return{ lua_touserdata(L, lua_upvalueindex(index)) };
}
};
template <>
struct getter<void*> {
void* get(lua_State* L, int index = 1) {
static void* get(lua_State* L, int index = 1) {
return lua_touserdata(L, index);
}
};
@ -316,15 +316,17 @@ struct pusher<std::string> {
}
};
inline void push(lua_State*) {
}
template<typename T, typename... Args>
inline void push(lua_State* L, T&& t, Args&&... args) {
pusher<Unqualified<T>>{}.push(L, std::forward<T>(t), std::forward<Args>(args)...);
}
// overload allows to use a pusher of a specific type, but pass in any kind of args
template<typename T, typename Arg, typename... Args>
inline void push(lua_State* L, Arg&& t, Args&&... args) {
pusher<Unqualified<T>>{}.push(L, std::forward<T>(t), std::forward<Args>(args)...);
}
inline void push_args(lua_State*) {
// do nothing
}