diff --git a/bootstrap.py b/bootstrap.py index c1f8541b..971392e2 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -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'])) diff --git a/sol/function.hpp b/sol/function.hpp index 9f7ca93b..77535d71 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -275,7 +275,7 @@ struct pusher> { template static void set_isconvertible_fx(std::false_type, types, lua_State* L, Fx&& fx) { typedef meta::Unwrapped> fx_t; - std::unique_ptr sptr = std::make_unique>(std::forward(fx)); + std::unique_ptr sptr = std::make_unique>(std::forward(fx)); set_fx(L, std::move(sptr)); } diff --git a/sol/function_types_allocator.hpp b/sol/function_types_allocator.hpp index c6bd2517..30c451dd 100644 --- a/sol/function_types_allocator.hpp +++ b/sol/function_types_allocator.hpp @@ -32,7 +32,7 @@ struct void_call; template struct void_call> { - static void call(Args... args) {} + static void call(Args...) {} }; template diff --git a/sol/function_types_member.hpp b/sol/function_types_member.hpp index 95addbe6..cd033472 100644 --- a/sol/function_types_member.hpp +++ b/sol/function_types_member.hpp @@ -38,7 +38,7 @@ struct functor_function : public base_function { template int operator()(types tr, types ta, lua_State* L) { - stack::call(tr, ta, L, 0,fx); + stack::call(tr, ta, L, 0, fx); int nargs = static_cast(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(m), std::forward(args)...) {} virtual int operator()(lua_State* L) override { - return stack::typed_call(meta::tuple_types(), args_types(), fx, L); + return stack::typed_call(meta::tuple_types(), args_types(), fx, L, 1); } }; } // function_detail diff --git a/sol/function_types_overload.hpp b/sol/function_types_overload.hpp index ed2f4e7f..56836b49 100644 --- a/sol/function_types_overload.hpp +++ b/sol/function_types_overload.hpp @@ -57,7 +57,7 @@ inline int overload_match_arity(types, std::index_sequence if (traits::arity != fxarity) { return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(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(), std::index_sequence(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); } return matchfx(meta::Bool(), types(), Index(), return_types(), args_type(), L, fxarity, start, std::forward(args)...); @@ -65,12 +65,12 @@ inline int overload_match_arity(types, std::index_sequence } // internals template -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(), std::index_sequence_for(), std::index_sequence<>(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); } template -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(std::forward(matchfx), L, fxarity, start, std::forward(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(args)...); }; - return overload_match(mfx, L); + return overload_match(mfx, L, 1); } }; @@ -110,13 +110,8 @@ struct usertype_overloaded_function : base_function { typedef std::tuple>>...> overload_list; typedef std::index_sequence_for indices; overload_list overloads; - - usertype_overloaded_function(overload_set set) : usertype_overloaded_function(indices(), set) {} - - template - usertype_overloaded_function(std::index_sequence, overload_set set) : usertype_overloaded_function(std::get(set)...) {} - - usertype_overloaded_function(Functions... fxs) : overloads(fxs...) {} + + usertype_overloaded_function(std::tuple set) : overloads(std::move(set)) {} template int call(meta::Bool, types, Index, types r, types a, lua_State* L, int, int start) { diff --git a/sol/function_types_static.hpp b/sol/function_types_static.hpp index 36e60977..535f02d5 100644 --- a/sol/function_types_static.hpp +++ b/sol/function_types_static.hpp @@ -34,7 +34,7 @@ struct static_function { static int call(lua_State* L) { auto udata = stack::stack_detail::get_as_upvalues(L); function_type* fx = udata.first; - int r = stack::typed_call(meta::tuple_types(), typename traits_type::args_type(), fx, L); + int r = stack::typed_call(meta::tuple_types(), 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(args)...); }; - return stack::typed_call(meta::tuple_types(), typename traits_type::args_type(), fx, L); + return stack::typed_call(meta::tuple_types(), typename traits_type::args_type(), fx, L, 1); } int operator()(lua_State* L) { diff --git a/sol/proxy.hpp b/sol/proxy.hpp index 22fd9531..46ba6f43 100644 --- a/sol/proxy.hpp +++ b/sol/proxy.hpp @@ -85,7 +85,7 @@ public: template decltype(auto) call(Args&&... args) { - return get().call(std::forward(args)...); + return get().template call(std::forward(args)...); } template diff --git a/sol/reference.hpp b/sol/reference.hpp index ab861bc6..83f3baaf 100644 --- a/sol/reference.hpp +++ b/sol/reference.hpp @@ -43,6 +43,10 @@ push_pop 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; diff --git a/sol/resolve.hpp b/sol/resolve.hpp index 2c269bac..74eeca4a 100644 --- a/sol/resolve.hpp +++ b/sol/resolve.hpp @@ -36,19 +36,19 @@ inline auto resolve_i(types, F&&) -> R(meta::Unqualified::*)(Args template> inline auto resolve_f(std::true_type, F&& f) --> decltype(resolve_i(types>(), std::forward(f))) { - return resolve_i(types>(), std::forward(f)); +-> decltype(resolve_i(types>(), std::forward(f))) { + return resolve_i(types>(), std::forward(f)); } template inline void resolve_f(std::false_type, F&&) { - static_assert(has_deducible_signature::value, + static_assert(meta::has_deducible_signature::value, "Cannot use no-template-parameter call with an overloaded functor: specify the signature"); } template> -inline auto resolve_i(types<>, F&& f) -> decltype(resolve_f(has_deducible_signature {}, std::forward(f))) { - return resolve_f(has_deducible_signature {}, std::forward(f)); +inline auto resolve_i(types<>, F&& f) -> decltype(resolve_f(meta::has_deducible_signature(), std::forward(f))) { + return resolve_f(meta::has_deducible_signature {}, std::forward(f)); } template> diff --git a/sol/stack.hpp b/sol/stack.hpp index 7f34d6c5..363e5518 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -175,7 +175,7 @@ struct userdata_pusher { template inline int push_tuple(std::index_sequence, lua_State* L, T&& tuplen) { int pushcount = 0; - detail::swallow{(pushcount += sol::stack::push(L, std::get(tuplen)), '\0')... }; + void(detail::swallow{(pushcount += sol::stack::push(L, std::get(tuplen)), '\0')... }); return pushcount; } @@ -218,64 +218,6 @@ inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) { } } // stack_detail -template -struct checker { - template - 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 -struct checker { - template - 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{}.check(L, indextype, index, handler); - } -}; - -template -struct checker { - template - 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::metatable[0]); - const type expectedmetatabletype = get(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 - 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 struct getter { static T& get(lua_State* L, int index = -1) { @@ -433,6 +375,64 @@ struct getter> { } }; +template +struct checker { + template + 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 +struct checker { + template + 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{}.check(L, indextype, index, handler); + } +}; + +template +struct checker { + template + 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::metatable[0]); + const type expectedmetatabletype = get(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 + 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 struct popper { inline decltype(auto) pop(lua_State* L) { @@ -656,7 +656,7 @@ struct field_getter, b, C> { template void apply(std::index_sequence, lua_State* L, Key&& key, int tableindex) { get_field(L, std::get(key), tableindex); - detail::swallow{ (get_field(L, std::get(key)), 0)... }; + void(detail::swallow{ (get_field(L, std::get(key)), 0)... }); reference saved(L, -1); lua_pop(L, static_cast(sizeof...(I) + 1)); saved.push(); @@ -853,7 +853,7 @@ inline void top_call(types tr, types ta, lua_State* L, Fx&& fx, F } template -inline int typed_call(types tr, types ta, Fx&& fx, lua_State* L, int start = 1, FxArgs&&... fxargs) { +inline int typed_call(types tr, types ta, Fx&& fx, lua_State* L, int start, FxArgs&&... fxargs) { call(tr, ta, L, start, fx, std::forward(fxargs)...); int nargs = static_cast(sizeof...(Args)); lua_pop(L, nargs); @@ -861,7 +861,7 @@ inline int typed_call(types tr, types ta, Fx&& fx, lua_State* L, } template>::value>> -inline int typed_call(types, types ta, Fx&& fx, lua_State* L, int start = 1, FxArgs&&... fxargs) { +inline int typed_call(types, types ta, Fx&& fx, lua_State* L, int start, FxArgs&&... fxargs) { decltype(auto) r = call(types>(), ta, L, start, fx, std::forward(fxargs)...); int nargs = static_cast(sizeof...(Args)); lua_pop(L, nargs); diff --git a/sol/state_view.hpp b/sol/state_view.hpp index 2b45db4c..32a04c1c 100644 --- a/sol/state_view.hpp +++ b/sol/state_view.hpp @@ -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_) { } diff --git a/sol/table_core.hpp b/sol/table_core.hpp index 8aa93ce7..deb5a0d9 100644 --- a/sol/table_core.hpp +++ b/sol/table_core.hpp @@ -28,10 +28,6 @@ #include "usertype.hpp" namespace sol { -namespace detail { -struct global_overload_tag { } const global_overload; -} // detail - template class table_core : public reference { friend class state; @@ -45,7 +41,7 @@ class table_core : public reference { -> decltype(stack::pop>(nullptr)){ auto pp = stack::push_popper(keys))...>::value>(*this); int tableindex = lua_gettop(lua_state()); - detail::swallow{ ( stack::get_field(lua_state(), std::get(keys), tableindex), 0)... }; + void(detail::swallow{ ( stack::get_field(lua_state(), std::get(keys), tableindex), 0)... }); return stack::pop>( lua_state() ); } @@ -59,7 +55,7 @@ class table_core : public reference { template void tuple_set( std::index_sequence, Pairs&& pairs ) { auto pp = stack::push_popper(pairs))...>::value>(*this); - detail::swallow{ (stack::set_field(lua_state(), std::get(pairs), std::get(pairs)), 0)... }; + void(detail::swallow{ (stack::set_field(lua_state(), std::get(pairs), std::get(pairs)), 0)... }); } template @@ -85,11 +81,8 @@ class table_core : public reference { traverse_set_deep(std::forward(keys)...); } -#if SOL_LUA_VERSION < 502 - table_core( detail::global_overload_tag, const table_core& reg ) noexcept : reference( reg.lua_state(), LUA_GLOBALSINDEX ) { } -#else - table_core( detail::global_overload_tag, const table& reg ) noexcept : reference( reg.get( 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& global ) : reference( global ) { } diff --git a/sol/traits.hpp b/sol/traits.hpp index 4da57bba..a12aaa08 100644 --- a/sol/traits.hpp +++ b/sol/traits.hpp @@ -73,7 +73,7 @@ using remove_member_pointer_t = remove_member_pointer; template class Templ> struct is_specialization_of : std::false_type { }; template class Templ> -struct meta::is_specialization_of, Templ> : std::true_type { }; +struct is_specialization_of, Templ> : std::true_type { }; template struct are_same : std::true_type { }; diff --git a/tests.cpp b/tests.cpp index 7ddfaa80..c9f6b26e 100644 --- a/tests.cpp +++ b/tests.cpp @@ -238,7 +238,7 @@ public: } }; - static const int true_a = 156; + static const int true_a; int a; static std::unique_ptr 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") {