Fixes for the g++/clang builds

This commit is contained in:
ThePhD 2015-06-18 10:53:21 -04:00
parent ffcd1f557b
commit 069a209a4e
3 changed files with 79 additions and 70 deletions

View File

@ -25,7 +25,9 @@
#include <lua.hpp> #include <lua.hpp>
#ifdef LUAJIT_VERSION #ifdef LUAJIT_VERSION
#ifndef SOL_LUAJIT
#define SOL_LUAJIT #define SOL_LUAJIT
#endif // sol luajit
#endif // luajit #endif // luajit
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502

View File

@ -73,56 +73,6 @@ struct return_forward {
} // detail } // detail
namespace stack { namespace stack {
namespace detail {
const bool default_check_arguments =
#ifdef SOL_CHECK_ARGUMENTS
true;
#else
false;
#endif
template <typename T, typename Key>
inline int push_userdata_pointer(lua_State* L, Key&& metatablekey) {
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey));
}
template <typename T, typename Key, typename Arg, EnableIf<std::is_same<T, Unqualified<Arg>>> = 0>
inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg&& arg) {
if (arg == nullptr)
return push(L, nil);
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey), std::forward<Arg>(arg));
}
template <typename T, typename Key, typename Arg, DisableIf<std::is_same<T, Unqualified<Arg>>> = 0>
inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg&& arg) {
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey), std::forward<Arg>(arg));
}
template <typename T, typename Key, typename Arg0, typename Arg1, typename... Args>
inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg0&& arg0, Arg1&& arg1, Args&&... args) {
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey), std::forward<Arg0>(arg0), std::forward<Arg1>(arg1), std::forward<Args>(args)...);
}
template <typename T, typename Key, typename... Args>
inline int push_confirmed_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
T* pdatum = static_cast<T*>(lua_newuserdata(L, sizeof(T)));
std::allocator<T> alloc{};
alloc.construct(pdatum, std::forward<Args>(args)...);
luaL_getmetatable(L, std::addressof(metatablekey[0]));
lua_setmetatable(L, -2);
return 1;
}
template<typename T, typename Key, typename... Args, DisableIf<std::is_pointer<T>> = 0>
inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey), std::forward<Args>(args)...);
}
template<typename T, typename Key, typename... Args, EnableIf<std::is_pointer<T>> = 0>
inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
return push_userdata_pointer<T>(L, std::forward<Key>(metatablekey), std::forward<Args>(args)...);
}
} // detail
template<typename T, typename = void> template<typename T, typename = void>
struct getter; struct getter;
@ -159,7 +109,7 @@ template<typename T, typename... Args>
inline int push_args(lua_State* L, T&& t, Args&&... args) { inline int push_args(lua_State* L, T&& t, Args&&... args) {
int pushcount = push(L, std::forward<T>(t)); int pushcount = push(L, std::forward<T>(t));
using swallow = char[]; using swallow = char[];
void(swallow{'\0', (pushcount += push(L, std::forward<Args>(args)), '\0')... }); void(swallow{'\0', (pushcount += sol::stack::push(L, std::forward<Args>(args)), '\0')... });
return pushcount; return pushcount;
} }
@ -176,6 +126,70 @@ auto pop(lua_State* L) -> decltype(get<T>(L)) {
return r; return r;
} }
template <typename T, typename Handler>
bool check(lua_State* L, int index, Handler&& handler) {
typedef Unqualified<T> Tu;
checker<Tu> c;
return c.check(L, index, std::forward<Handler>(handler));
}
template <typename T>
bool check(lua_State* L, int index) {
auto handler = type_panic;
return check<T>(L, index, handler);
}
namespace detail {
const bool default_check_arguments =
#ifdef SOL_CHECK_ARGUMENTS
true;
#else
false;
#endif
template <typename T, typename Key, typename... Args>
inline int push_confirmed_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
T* pdatum = static_cast<T*>(lua_newuserdata(L, sizeof(T)));
std::allocator<T> alloc{};
alloc.construct(pdatum, std::forward<Args>(args)...);
luaL_getmetatable(L, std::addressof(metatablekey[0]));
lua_setmetatable(L, -2);
return 1;
}
template <typename T, typename Key>
inline int push_userdata_pointer(lua_State* L, Key&& metatablekey) {
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey));
}
template <typename T, typename Key, typename Arg, EnableIf<std::is_same<T, Unqualified<Arg>>> = 0>
inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg&& arg) {
if (arg == nullptr)
return push(L, nil);
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey), std::forward<Arg>(arg));
}
template <typename T, typename Key, typename Arg, DisableIf<std::is_same<T, Unqualified<Arg>>> = 0>
inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg&& arg) {
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey), std::forward<Arg>(arg));
}
template <typename T, typename Key, typename Arg0, typename Arg1, typename... Args>
inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg0&& arg0, Arg1&& arg1, Args&&... args) {
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey), std::forward<Arg0>(arg0), std::forward<Arg1>(arg1), std::forward<Args>(args)...);
}
template<typename T, typename Key, typename... Args, DisableIf<std::is_pointer<T>> = 0>
inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
return push_confirmed_userdata<T>(L, std::forward<Key>(metatablekey), std::forward<Args>(args)...);
}
template<typename T, typename Key, typename... Args, EnableIf<std::is_pointer<T>> = 0>
inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
return push_userdata_pointer<T>(L, std::forward<Key>(metatablekey), std::forward<Args>(args)...);
}
} // detail
template<typename T> template<typename T>
struct get_return { struct get_return {
typedef decltype(get<T>(nullptr)) type; typedef decltype(get<T>(nullptr)) type;
@ -210,19 +224,6 @@ struct checker<T*, expected, C> {
} }
}; };
template <typename T, typename Handler>
bool check(lua_State* L, int index, Handler&& handler) {
typedef Unqualified<T> Tu;
checker<Tu> c;
return c.check(L, index, std::forward<Handler>(handler));
}
template <typename T>
bool check(lua_State* L, int index) {
auto handler = type_panic;
return check<T>(L, index, handler);
}
template<typename T, typename> template<typename T, typename>
struct getter { struct getter {
template<typename U = T, EnableIf<std::is_floating_point<U>> = 0> template<typename U = T, EnableIf<std::is_floating_point<U>> = 0>
@ -548,15 +549,20 @@ inline std::pair<T, int> get_as_upvalues(lua_State* L, int index = 1) {
template <bool b> template <bool b>
struct check_arguments { struct check_arguments {
template <std::size_t... I, typename... Args> template <std::size_t I0, std::size_t... I, typename Arg0, typename... Args>
static bool check(lua_State* L, int firstargument, indices<I...>, types<Args...>) { static bool check(lua_State* L, int firstargument, indices<I0, I...>, types<Arg0, Args...>) {
bool checks = true; bool checks = true;
stack::check<Arg0>(L, firstargument + I0);
using swallow = int[sizeof...(Args)+2]; using swallow = int[sizeof...(Args)+2];
(void)swallow { (void)swallow {
0, (checks &= stack::check<Args>(L, firstargument + I))..., 0 0, (checks &= stack::check<Args>(L, firstargument + I))..., 0
}; };
return checks; return checks;
} }
static bool check(lua_State*, int, indices<>, types<>) {
return true;
}
}; };
template <> template <>

View File

@ -95,12 +95,12 @@ public:
luaL_requiref(L.get(), "package", luaopen_package, 1); luaL_requiref(L.get(), "package", luaopen_package, 1);
lua_pop(L.get(), 1); lua_pop(L.get(), 1);
break; break;
#if SOL_LUA_VERSION > 501
case lib::coroutine: case lib::coroutine:
#if SOL_LUA_VERSION > 501
luaL_requiref(L.get(), "coroutine", luaopen_coroutine, 1); luaL_requiref(L.get(), "coroutine", luaopen_coroutine, 1);
lua_pop(L.get(), 1); lua_pop(L.get(), 1);
break;
#endif // Lua 5.2+ only #endif // Lua 5.2+ only
break;
case lib::string: case lib::string:
luaL_requiref(L.get(), "string", luaopen_string, 1); luaL_requiref(L.get(), "string", luaopen_string, 1);
lua_pop(L.get(), 1); lua_pop(L.get(), 1);
@ -113,12 +113,13 @@ public:
luaL_requiref(L.get(), "math", luaopen_math, 1); luaL_requiref(L.get(), "math", luaopen_math, 1);
lua_pop(L.get(), 1); lua_pop(L.get(), 1);
break; break;
#if SOL_LUA_VERSION > 510
case lib::bit32: case lib::bit32:
#if SOL_LUA_VERSION > 510
luaL_requiref(L.get(), "bit32", luaopen_bit32, 1); luaL_requiref(L.get(), "bit32", luaopen_bit32, 1);
lua_pop(L.get(), 1); lua_pop(L.get(), 1);
break; #else
#endif // Lua 5.2+ only #endif // Lua 5.2+ only
break;
case lib::io: case lib::io:
luaL_requiref(L.get(), "io", luaopen_io, 1); luaL_requiref(L.get(), "io", luaopen_io, 1);
lua_pop(L.get(), 1); lua_pop(L.get(), 1);