Proper defaults for bootstrap.py

Checks in g++ to make sure things compile
clang++ is a major asshole...
This commit is contained in:
ThePhD 2016-02-24 13:59:17 -05:00
parent e046435b49
commit 9c21d11b8c
14 changed files with 102 additions and 103 deletions

View File

@ -32,8 +32,8 @@ def replace_extension(f, e):
# Default install dir
install_dir = os.path.join('/usr', 'include') if 'linux' in sys.platform else 'include'
# Compiler: Read from environment
cxx = os.environ['CXX']
# Compiler: Read from environment or defaulted
cxx = os.environ.get('CXX', "g++")
# command line stuff
parser = argparse.ArgumentParser()
@ -78,9 +78,9 @@ if args.lua_dir:
ldflags.extend(library_includes([os.path.join(args.lua_dir, 'lib')]))
if args.ci:
ldflags.extend(libraries(['lua5.2']))
ldflags.extend(libraries(['lua5.3']))
ldflags.extend(library_includes(['lib']))
include.extend(['/usr/include/lua5.2', './lua-5.2.2/src', './include'])
include.extend(['/usr/include/lua5.3', './lua-5.3.2/src', './include'])
else:
ldflags.extend(libraries(['lua']))

View File

@ -275,7 +275,7 @@ struct pusher<function_sig<Sigs...>> {
template<typename Fx, typename R, typename... Args>
static void set_isconvertible_fx(std::false_type, types<R(Args...)>, lua_State* L, Fx&& fx) {
typedef meta::Unwrapped<std::decay_t<Fx>> fx_t;
std::unique_ptr<base_function> sptr = std::make_unique<function_detail::functor_function<fx_t>>(std::forward<Fx>(fx));
std::unique_ptr<function_detail::base_function> sptr = std::make_unique<function_detail::functor_function<fx_t>>(std::forward<Fx>(fx));
set_fx<Fx>(L, std::move(sptr));
}

View File

@ -32,7 +32,7 @@ struct void_call;
template <typename T, typename... Args>
struct void_call<T, types<Args...>> {
static void call(Args... args) {}
static void call(Args...) {}
};
template <typename T>

View File

@ -38,7 +38,7 @@ struct functor_function : public base_function {
template<typename... Args>
int operator()(types<void> tr, types<Args...> ta, lua_State* L) {
stack::call(tr, ta, L, 0,fx);
stack::call(tr, ta, L, 0, fx);
int nargs = static_cast<int>(sizeof...(Args));
lua_pop(L, nargs);
return 0;
@ -80,7 +80,7 @@ struct member_function : public base_function {
member_function(Tm&& m, Args&&... args): fx(std::forward<Tm>(m), std::forward<Args>(args)...) {}
virtual int operator()(lua_State* L) override {
return stack::typed_call(meta::tuple_types<return_type>(), args_types(), fx, L);
return stack::typed_call(meta::tuple_types<return_type>(), args_types(), fx, L, 1);
}
};
} // function_detail

View File

@ -57,7 +57,7 @@ inline int overload_match_arity(types<Fx, Fxs...>, std::index_sequence<I, In...>
if (traits::arity != fxarity) {
return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<traits::arity, M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
}
if (sizeof...(Fxs) != 0 && function_detail::check_types(args_type(), args_indices(), L, start)) {
if (sizeof...(Fxs) != 0 && !function_detail::check_types(args_type(), args_indices(), L, start)) {
return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
}
return matchfx(meta::Bool<sizeof...(Fxs) != 0>(), types<Fx>(), Index<I>(), return_types(), args_type(), L, fxarity, start, std::forward<Args>(args)...);
@ -65,12 +65,12 @@ inline int overload_match_arity(types<Fx, Fxs...>, std::index_sequence<I, In...>
} // internals
template <typename... Functions, typename Match, typename... Args>
inline int overload_match_arity(Match&& matchfx, lua_State* L, int fxarity, int start = 1, Args&&... args) {
inline int overload_match_arity(Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) {
return internals::overload_match_arity(types<Functions...>(), std::index_sequence_for<Functions...>(), std::index_sequence<>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
}
template <typename... Functions, typename Match, typename... Args>
inline int overload_match(Match&& matchfx, lua_State* L, int start = 1, Args&&... args) {
inline int overload_match(Match&& matchfx, lua_State* L, int start, Args&&... args) {
int fxarity = lua_gettop(L) - (start - 1);
return overload_match_arity<Functions...>(std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
}
@ -101,7 +101,7 @@ struct overloaded_function : base_function {
virtual int operator()(lua_State* L) override {
auto mfx = [&](auto&&... args){ return this->call(std::forward<decltype(args)>(args)...); };
return overload_match<Functions...>(mfx, L);
return overload_match<Functions...>(mfx, L, 1);
}
};
@ -110,13 +110,8 @@ struct usertype_overloaded_function : base_function {
typedef std::tuple<functor<T, std::remove_pointer_t<std::decay_t<Functions>>>...> overload_list;
typedef std::index_sequence_for<Functions...> indices;
overload_list overloads;
usertype_overloaded_function(overload_set<Functions...> set) : usertype_overloaded_function(indices(), set) {}
template <std::size_t... I>
usertype_overloaded_function(std::index_sequence<I...>, overload_set<Functions...> set) : usertype_overloaded_function(std::get<I>(set)...) {}
usertype_overloaded_function(Functions... fxs) : overloads(fxs...) {}
usertype_overloaded_function(std::tuple<Functions...> set) : overloads(std::move(set)) {}
template <bool b,typename Fx, std::size_t I, typename... R, typename... Args>
int call(meta::Bool<b>, types<Fx>, Index<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) {

View File

@ -34,7 +34,7 @@ struct static_function {
static int call(lua_State* L) {
auto udata = stack::stack_detail::get_as_upvalues<function_type*>(L);
function_type* fx = udata.first;
int r = stack::typed_call(meta::tuple_types<typename traits_type::return_type>(), typename traits_type::args_type(), fx, L);
int r = stack::typed_call(meta::tuple_types<typename traits_type::return_type>(), typename traits_type::args_type(), fx, L, 1);
return r;
}
@ -54,7 +54,7 @@ struct static_member_function {
function_type& memfx = memberdata.first;
T& item = *objdata.first;
auto fx = [&item, &memfx](auto&&... args) -> typename traits_type::return_type { return (item.*memfx)(std::forward<decltype(args)>(args)...); };
return stack::typed_call(meta::tuple_types<typename traits_type::return_type>(), typename traits_type::args_type(), fx, L);
return stack::typed_call(meta::tuple_types<typename traits_type::return_type>(), typename traits_type::args_type(), fx, L, 1);
}
int operator()(lua_State* L) {

View File

@ -85,7 +85,7 @@ public:
template<typename... Ret, typename... Args>
decltype(auto) call(Args&&... args) {
return get<function>().call<Ret...>(std::forward<Args>(args)...);
return get<function>().template call<Ret...>(std::forward<Args>(args)...);
}
template<typename... Args>

View File

@ -43,6 +43,10 @@ push_pop<top_level, T> push_popper(T&& x) {
}
} // stack
namespace detail {
struct global_tag { } const global_{};
} // detail
class reference {
private:
lua_State* L = nullptr; // non-owning
@ -54,6 +58,12 @@ private:
push();
return luaL_ref(L, LUA_REGISTRYINDEX);
}
protected:
reference(lua_State* L, detail::global_tag) : L(L) {
lua_pushglobaltable(L);
ref = luaL_ref(L, LUA_REGISTRYINDEX);
}
public:
reference() noexcept = default;

View File

@ -36,19 +36,19 @@ inline auto resolve_i(types<R(Args...)>, F&&) -> R(meta::Unqualified<F>::*)(Args
template<typename F, typename U = meta::Unqualified<F>>
inline auto resolve_f(std::true_type, F&& f)
-> decltype(resolve_i(types<function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f))) {
return resolve_i(types<function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f));
-> decltype(resolve_i(types<meta::function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f))) {
return resolve_i(types<meta::function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f));
}
template<typename F>
inline void resolve_f(std::false_type, F&&) {
static_assert(has_deducible_signature<F>::value,
static_assert(meta::has_deducible_signature<F>::value,
"Cannot use no-template-parameter call with an overloaded functor: specify the signature");
}
template<typename F, typename U = meta::Unqualified<F>>
inline auto resolve_i(types<>, F&& f) -> decltype(resolve_f(has_deducible_signature<U> {}, std::forward<F>(f))) {
return resolve_f(has_deducible_signature<U> {}, std::forward<F>(f));
inline auto resolve_i(types<>, F&& f) -> decltype(resolve_f(meta::has_deducible_signature<U>(), std::forward<F>(f))) {
return resolve_f(meta::has_deducible_signature<U> {}, std::forward<F>(f));
}
template<typename... Args, typename F, typename R = std::result_of_t<F&(Args...)>>

View File

@ -175,7 +175,7 @@ struct userdata_pusher<T*> {
template<typename T, std::size_t... I>
inline int push_tuple(std::index_sequence<I...>, lua_State* L, T&& tuplen) {
int pushcount = 0;
detail::swallow{(pushcount += sol::stack::push(L, std::get<I>(tuplen)), '\0')... };
void(detail::swallow{(pushcount += sol::stack::push(L, std::get<I>(tuplen)), '\0')... });
return pushcount;
}
@ -218,64 +218,6 @@ inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
}
} // stack_detail
template <typename T, type expected, typename>
struct checker {
template <typename Handler>
static bool check (lua_State* L, int index, const Handler& handler) {
const type indextype = type_of(L, index);
bool success = expected == indextype;
if (!success) {
// expected type, actual type
handler(L, index, expected, indextype);
}
return success;
}
};
template <typename T, typename C>
struct checker<T*, type::userdata, C> {
template <typename Handler>
static bool check (lua_State* L, int index, const Handler& handler) {
const type indextype = type_of(L, index);
// Allow nil to be transformed to nullptr
if (indextype == type::nil) {
return true;
}
return checker<T, type::userdata, C>{}.check(L, indextype, index, handler);
}
};
template <typename T,typename C>
struct checker<T, type::userdata, C> {
template <typename Handler>
static bool check (lua_State* L, type indextype, int index, const Handler& handler) {
if (indextype != type::userdata) {
handler(L, index, type::userdata, indextype);
return false;
}
if (lua_getmetatable(L, index) == 0) {
handler(L, index, type::userdata, indextype);
return false;
}
luaL_getmetatable(L, &usertype_traits<T>::metatable[0]);
const type expectedmetatabletype = get<type>(L);
if (expectedmetatabletype == type::nil) {
lua_pop(L, 2);
handler(L, index, type::userdata, indextype);
return false;
}
bool success = lua_rawequal(L, -1, -2) == 1;
lua_pop(L, 2);
return success;
}
template <typename Handler>
static bool check (lua_State* L, int index, const Handler& handler) {
const type indextype = type_of(L, index);
return check(L, indextype, index, handler);
}
};
template<typename T, typename>
struct getter {
static T& get(lua_State* L, int index = -1) {
@ -433,6 +375,64 @@ struct getter<std::tuple<Args...>> {
}
};
template <typename T, type expected, typename>
struct checker {
template <typename Handler>
static bool check (lua_State* L, int index, const Handler& handler) {
const type indextype = type_of(L, index);
bool success = expected == indextype;
if (!success) {
// expected type, actual type
handler(L, index, expected, indextype);
}
return success;
}
};
template <typename T, typename C>
struct checker<T*, type::userdata, C> {
template <typename Handler>
static bool check (lua_State* L, int index, const Handler& handler) {
const type indextype = type_of(L, index);
// Allow nil to be transformed to nullptr
if (indextype == type::nil) {
return true;
}
return checker<T, type::userdata, C>{}.check(L, indextype, index, handler);
}
};
template <typename T,typename C>
struct checker<T, type::userdata, C> {
template <typename Handler>
static bool check (lua_State* L, type indextype, int index, const Handler& handler) {
if (indextype != type::userdata) {
handler(L, index, type::userdata, indextype);
return false;
}
if (lua_getmetatable(L, index) == 0) {
handler(L, index, type::userdata, indextype);
return false;
}
luaL_getmetatable(L, &usertype_traits<T>::metatable[0]);
const type expectedmetatabletype = get<type>(L);
if (expectedmetatabletype == type::nil) {
lua_pop(L, 2);
handler(L, index, type::userdata, indextype);
return false;
}
bool success = lua_rawequal(L, -1, -2) == 1;
lua_pop(L, 2);
return success;
}
template <typename Handler>
static bool check (lua_State* L, int index, const Handler& handler) {
const type indextype = type_of(L, index);
return check(L, indextype, index, handler);
}
};
template <typename T, typename>
struct popper {
inline decltype(auto) pop(lua_State* L) {
@ -656,7 +656,7 @@ struct field_getter<std::tuple<Args...>, b, C> {
template <std::size_t I0, std::size_t... I, typename Key>
void apply(std::index_sequence<I0, I...>, lua_State* L, Key&& key, int tableindex) {
get_field<b>(L, std::get<I0>(key), tableindex);
detail::swallow{ (get_field(L, std::get<I>(key)), 0)... };
void(detail::swallow{ (get_field(L, std::get<I>(key)), 0)... });
reference saved(L, -1);
lua_pop(L, static_cast<int>(sizeof...(I) + 1));
saved.push();
@ -853,7 +853,7 @@ inline void top_call(types<void> tr, types<Args...> ta, lua_State* L, Fx&& fx, F
}
template<bool check_args = stack_detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
inline int typed_call(types<void> tr, types<Args...> ta, Fx&& fx, lua_State* L, int start = 1, FxArgs&&... fxargs) {
inline int typed_call(types<void> tr, types<Args...> ta, Fx&& fx, lua_State* L, int start, FxArgs&&... fxargs) {
call<check_args>(tr, ta, L, start, fx, std::forward<FxArgs>(fxargs)...);
int nargs = static_cast<int>(sizeof...(Args));
lua_pop(L, nargs);
@ -861,7 +861,7 @@ inline int typed_call(types<void> tr, types<Args...> ta, Fx&& fx, lua_State* L,
}
template<bool check_args = stack_detail::default_check_arguments, typename Ret0, typename... Ret, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<meta::Not<std::is_void<Ret0>>::value>>
inline int typed_call(types<Ret0, Ret...>, types<Args...> ta, Fx&& fx, lua_State* L, int start = 1, FxArgs&&... fxargs) {
inline int typed_call(types<Ret0, Ret...>, types<Args...> ta, Fx&& fx, lua_State* L, int start, FxArgs&&... fxargs) {
decltype(auto) r = call<check_args>(types<meta::return_type_t<Ret0, Ret...>>(), ta, L, start, fx, std::forward<FxArgs>(fxargs)...);
int nargs = static_cast<int>(sizeof...(Args));
lua_pop(L, nargs);

View File

@ -58,7 +58,7 @@ public:
state_view(lua_State* L):
L(L),
reg(L, LUA_REGISTRYINDEX),
globals(detail::global_overload, reg) {
globals(L, detail::global_) {
}

View File

@ -28,10 +28,6 @@
#include "usertype.hpp"
namespace sol {
namespace detail {
struct global_overload_tag { } const global_overload;
} // detail
template <bool top_level>
class table_core : public reference {
friend class state;
@ -45,7 +41,7 @@ class table_core : public reference {
-> decltype(stack::pop<std::tuple<Ret...>>(nullptr)){
auto pp = stack::push_popper<is_global<decltype(std::get<I>(keys))...>::value>(*this);
int tableindex = lua_gettop(lua_state());
detail::swallow{ ( stack::get_field<top_level>(lua_state(), std::get<I>(keys), tableindex), 0)... };
void(detail::swallow{ ( stack::get_field<top_level>(lua_state(), std::get<I>(keys), tableindex), 0)... });
return stack::pop<std::tuple<Ret...>>( lua_state() );
}
@ -59,7 +55,7 @@ class table_core : public reference {
template<typename Pairs, std::size_t... I>
void tuple_set( std::index_sequence<I...>, Pairs&& pairs ) {
auto pp = stack::push_popper<is_global<decltype(std::get<I * 2>(pairs))...>::value>(*this);
detail::swallow{ (stack::set_field<top_level>(lua_state(), std::get<I * 2>(pairs), std::get<I * 2 + 1>(pairs)), 0)... };
void(detail::swallow{ (stack::set_field<top_level>(lua_state(), std::get<I * 2>(pairs), std::get<I * 2 + 1>(pairs)), 0)... });
}
template <bool global, typename T, typename Key>
@ -85,11 +81,8 @@ class table_core : public reference {
traverse_set_deep<false>(std::forward<Keys>(keys)...);
}
#if SOL_LUA_VERSION < 502
table_core( detail::global_overload_tag, const table_core<false>& reg ) noexcept : reference( reg.lua_state(), LUA_GLOBALSINDEX ) { }
#else
table_core( detail::global_overload_tag, const table& reg ) noexcept : reference( reg.get<table>( LUA_RIDX_GLOBALS ) ) { }
#endif
table_core(lua_State* L, detail::global_tag t) noexcept : reference(L, t) { }
public:
table_core( ) noexcept : reference( ) { }
table_core( const table_core<true>& global ) : reference( global ) { }

View File

@ -73,7 +73,7 @@ using remove_member_pointer_t = remove_member_pointer<T>;
template<typename T, template<typename...> class Templ>
struct is_specialization_of : std::false_type { };
template<typename... T, template<typename...> class Templ>
struct meta::is_specialization_of<Templ<T...>, Templ> : std::true_type { };
struct is_specialization_of<Templ<T...>, Templ> : std::true_type { };
template<class T, class...>
struct are_same : std::true_type { };

View File

@ -238,7 +238,7 @@ public:
}
};
static const int true_a = 156;
static const int true_a;
int a;
static std::unique_ptr<factory_test, deleter> make() {
@ -258,6 +258,7 @@ public:
int factory_test::num_saved = 0;
int factory_test::num_killed = 0;
const int factory_test::true_a = 156;
TEST_CASE("table/traversal", "ensure that we can chain requests and tunnel down into a value if we desire") {