From aad954d2c04efeff7d248962b0d3ea25ae52c827 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sat, 10 Mar 2018 20:45:46 -0500 Subject: [PATCH] update single --- single/sol/sol.hpp | 263 +++++++++++++++++++++++++++++-------- single/sol/sol_forward.hpp | 4 +- 2 files changed, 209 insertions(+), 58 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index b3fed9a3..f68eadde 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2018-03-10 04:31:26.815848 UTC -// This header was generated with sol v2.19.5 (revision 623a38e) +// Generated 2018-03-11 01:45:34.909172 UTC +// This header was generated with sol v2.19.5 (revision a83091c) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -4517,8 +4517,28 @@ namespace sol { #ifdef SOL_CXX17_FEATURES #include #endif // C++17 +#ifdef SOL_USE_BOOST +#include +#else +#include +#endif // Using Boost namespace sol { + namespace usertype_detail { +#if defined(SOL_USE_BOOST) +#if defined(SOL_CXX17_FEATURES) + template , typename E = std::equal_to<>> + using map_t = boost::unordered_map; +#else + template , typename E = std::equal_to<>> + using map_t = boost::unordered_map; +#endif // C++17 or not, WITH boost +#else + template , typename E = std::equal_to<>> + using map_t = std::unordered_map; +#endif // Boost map target + } + namespace detail { #ifdef SOL_NOEXCEPT_FUNCTION_TYPE typedef int(*lua_CFunction_noexcept)(lua_State* L) noexcept; @@ -5207,9 +5227,10 @@ namespace sol { "__pairs", "__ipairs", - "__next", + "next", "__type", - "__typeinfo" } }; + "__typeinfo" + } }; return names; } @@ -15477,8 +15498,6 @@ namespace sol { // beginning of sol/container_traits.hpp -#include - namespace sol { template @@ -15716,6 +15735,21 @@ namespace sol { static const bool value = sizeof(test(0)) == sizeof(char); }; + template + struct has_traits_at_test { + private: + typedef std::array one; + typedef std::array two; + + template + static one test(decltype(&C::at)); + template + static two test(...); + + public: + static const bool value = sizeof(test(0)) == sizeof(char); + }; + template struct has_traits_pairs_test { private: @@ -15746,6 +15780,21 @@ namespace sol { static const bool value = sizeof(test(0)) == sizeof(char); }; + template + struct has_traits_next_test { + private: + typedef std::array one; + typedef std::array two; + + template + static one test(decltype(&C::next)); + template + static two test(...); + + public: + static const bool value = sizeof(test(0)) == sizeof(char); + }; + template struct has_traits_add_test { private: @@ -15779,6 +15828,9 @@ namespace sol { template using has_traits_get = meta::boolean::value>; + template + using has_traits_at = meta::boolean::value>; + template using has_traits_set = meta::boolean::value>; @@ -15794,6 +15846,9 @@ namespace sol { template using has_traits_ipairs = meta::boolean::value>; + template + using has_traits_next = meta::boolean::value>; + template using has_traits_add = meta::boolean::value>; @@ -15886,6 +15941,10 @@ namespace sol { typedef lua_nil_t iterator; typedef lua_nil_t value_type; + static int at(lua_State* L) { + return luaL_error(L, "sol: cannot call 'at(index)' on type '%s': it is not recognized as a container", detail::demangle().c_str()); + } + static int get(lua_State* L) { return luaL_error(L, "sol: cannot call 'get(key)' on type '%s': it is not recognized as a container", detail::demangle().c_str()); } @@ -15930,8 +15989,12 @@ namespace sol { return luaL_error(L, "sol: cannot call 'erase' on type '%s': it is not recognized as a container", detail::demangle().c_str()); } + static int next(lua_State* L) { + return luaL_error(L, "sol: cannot call 'next' on type '%s': it is not recognized as a container", detail::demangle().c_str()); + } + static int pairs(lua_State* L) { - return luaL_error(L, "sol: cannot call '__pairs' on type '%s': it is not recognized as a container", detail::demangle().c_str()); + return luaL_error(L, "sol: cannot call '__pairs/pairs' on type '%s': it is not recognized as a container", detail::demangle().c_str()); } static int ipairs(lua_State* L) { @@ -16017,6 +16080,40 @@ namespace sol { #endif // Safe getting with error } + static error_result at_category(std::input_iterator_tag, lua_State* L, T& self, std::ptrdiff_t pos) { + pos += deferred_traits::index_adjustment(L, self); + if (pos < 0) { + return stack::push(L, lua_nil); + } + auto it = deferred_traits::begin(L, self); + auto e = deferred_traits::end(L, self); + if (it == e) { + return stack::push(L, lua_nil); + } + while (pos > 0) { + --pos; + ++it; + if (it == e) { + return stack::push(L, lua_nil); + } + } + return get_associative(is_associative(), L, it); + } + + static error_result at_category(std::random_access_iterator_tag, lua_State* L, T& self, std::ptrdiff_t pos) { + std::ptrdiff_t len = static_cast(size_start(L, self)); + pos += deferred_traits::index_adjustment(L, self); + if (pos < 0 || pos >= len) { + return stack::push(L, lua_nil); + } + auto it = std::next(deferred_traits::begin(L, self), pos); + return get_associative(is_associative(), L, it); + } + + static error_result at_start(lua_State* L, T& self, std::ptrdiff_t pos) { + return at_category(iterator_category(), L, self, pos); + } + static error_result get_associative(std::true_type, lua_State* L, iterator& it) { auto& v = *it; return stack::stack_detail::push_reference(L, detail::deref_non_pointer(v.second)); @@ -16248,8 +16345,8 @@ namespace sol { return error_result("cannot call 'add' on type '%s': no suitable insert/push_back C++ functions", detail::demangle().data()); } - static error_result add_insert_after(std::true_type, lua_State*, T& self, stack_object value, iterator& at) { - self.insert_after(at, value.as()); + static error_result add_insert_after(std::true_type, lua_State*, T& self, stack_object value, iterator& pos) { + self.insert_after(pos, value.as()); return {}; } @@ -16263,18 +16360,18 @@ namespace sol { return add_insert_after(std::true_type(), L, self, value, backit); } - static error_result add_insert(std::true_type, lua_State*, T& self, stack_object value, iterator& at) { - self.insert(at, value.as()); + static error_result add_insert(std::true_type, lua_State*, T& self, stack_object value, iterator& pos) { + self.insert(pos, value.as()); return {}; } static error_result add_insert(std::true_type, lua_State* L, T& self, stack_object value) { - auto at = deferred_traits::end(L, self); - return add_insert(std::true_type(), L, self, value, at); + auto pos = deferred_traits::end(L, self); + return add_insert(std::true_type(), L, self, value, pos); } - static error_result add_insert(std::false_type, lua_State* L, T& self, stack_object value, iterator& at) { - return add_insert_after(meta::has_insert_after(), L, self, std::move(value), at); + static error_result add_insert(std::false_type, lua_State* L, T& self, stack_object value, iterator& pos) { + return add_insert_after(meta::has_insert_after(), L, self, std::move(value), pos); } static error_result add_insert(std::false_type, lua_State* L, T& self, stack_object value) { @@ -16291,34 +16388,34 @@ namespace sol { return {}; } - static error_result add_push_back(std::false_type, lua_State* L, T& self, stack_object value, iterator& at) { - return add_insert(meta::has_insert(), L, self, value, at); + static error_result add_push_back(std::false_type, lua_State* L, T& self, stack_object value, iterator& pos) { + return add_insert(meta::has_insert(), L, self, value, pos); } static error_result add_push_back(std::false_type, lua_State* L, T& self, stack_object value) { return add_insert(meta::has_insert(), L, self, value); } - static error_result add_associative(std::true_type, lua_State* L, T& self, stack_object key, iterator& at) { - self.insert(at, value_type(key.as(), stack::get(L, 3))); + static error_result add_associative(std::true_type, lua_State* L, T& self, stack_object key, iterator& pos) { + self.insert(pos, value_type(key.as(), stack::get(L, 3))); return {}; } static error_result add_associative(std::true_type, lua_State* L, T& self, stack_object key) { - auto at = deferred_traits::end(L, self); - return add_associative(std::true_type(), L, self, std::move(key), at); + auto pos = deferred_traits::end(L, self); + return add_associative(std::true_type(), L, self, std::move(key), pos); } - static error_result add_associative(std::false_type, lua_State* L, T& self, stack_object value, iterator& at) { - return add_push_back(meta::has_push_back(), L, self, value, at); + static error_result add_associative(std::false_type, lua_State* L, T& self, stack_object value, iterator& pos) { + return add_push_back(meta::has_push_back(), L, self, value, pos); } static error_result add_associative(std::false_type, lua_State* L, T& self, stack_object value) { return add_push_back(meta::has_push_back(), L, self, value); } - static error_result add_copyable(std::true_type, lua_State* L, T& self, stack_object value, iterator& at) { - return add_associative(is_associative(), L, self, std::move(value), at); + static error_result add_copyable(std::true_type, lua_State* L, T& self, stack_object value, iterator& pos) { + return add_associative(is_associative(), L, self, std::move(value), pos); } static error_result add_copyable(std::true_type, lua_State* L, T& self, stack_object value) { @@ -16528,7 +16625,7 @@ namespace sol { } template - static int next(lua_State* L) { + static int next_iter(lua_State* L) { typedef meta::any>> is_assoc; return next_associative(is_assoc(), L); } @@ -16536,7 +16633,7 @@ namespace sol { template static int pairs_associative(std::true_type, lua_State* L) { auto& src = get_src(L); - stack::push(L, next); + stack::push(L, next_iter); stack::push>(L, src, deferred_traits::begin(L, src)); stack::push(L, lua_nil); return 3; @@ -16545,13 +16642,23 @@ namespace sol { template static int pairs_associative(std::false_type, lua_State* L) { auto& src = get_src(L); - stack::push(L, next); + stack::push(L, next_iter); stack::push>(L, src, deferred_traits::begin(L, src)); stack::push(L, 0); return 3; } public: + static int at(lua_State* L) { + auto& self = get_src(L); + error_result er; + { + std::ptrdiff_t pos = stack::get(L); + er = at_start(L, self, pos); + } + return handle_errors(L, er); + } + static int get(lua_State* L) { auto& self = get_src(L); error_result er; @@ -16648,6 +16755,10 @@ namespace sol { typedef meta::any>> is_assoc; return pairs_associative(is_assoc(), L); } + + static int next(lua_State* L) { + return stack::push(L, next_iter); + } }; template @@ -16673,8 +16784,11 @@ namespace sol { static auto& get_src(lua_State* L) { auto p = stack::check_get(L, 1); #ifdef SOL_SAFE_USERTYPE - if (!p || p.value() == nullptr) { - luaL_error(L, "sol: 'self' argument is nil or not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", detail::demangle().c_str()); + if (!p) { + luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", detail::demangle().c_str()); + } + if (p.value() == nullptr) { + luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument with ':' or call on a '%s' type)", detail::demangle().c_str()); } #endif // Safe getting with error return *p.value(); @@ -16697,7 +16811,7 @@ namespace sol { return luaL_error(L, "sol: cannot call 'find' on '%s': no supported comparison operator for the value type", detail::demangle().c_str()); } - static int next(lua_State* L) { + static int next_iter(lua_State* L) { iter& i = stack::get>(L, 1); auto& source = i.source; auto& it = i.it; @@ -16729,6 +16843,10 @@ namespace sol { return luaL_error(L, "sol: cannot call 'insert' on type '%s': cannot insert new entries into fixed arrays", detail::demangle().c_str()); } + static int at(lua_State* L) { + return get(L); + } + static int get(lua_State* L) { T& self = get_src(L); std::ptrdiff_t idx = stack::get(L, 2); @@ -16775,7 +16893,7 @@ namespace sol { static int pairs(lua_State* L) { auto& src = get_src(L); - stack::push(L, next); + stack::push(L, next_iter); stack::push>(L, src, deferred_traits::begin(L, src)); stack::push(L, 0); return 3; @@ -16785,6 +16903,10 @@ namespace sol { return pairs(L); } + static int next(lua_State* L) { + return stack::push(L, next_iter); + } + static std::ptrdiff_t index_adjustment(lua_State*, T&) { return -1; } @@ -16826,7 +16948,9 @@ namespace sol { } static int real_index_call(lua_State* L) { - static std::unordered_map calls{ + typedef usertype_detail::map_t call_map; + static const call_map calls{ + { "at", &at_call }, { "get", &real_get_call }, { "set", &real_set_call }, { "size", &real_length_call }, @@ -16835,12 +16959,19 @@ namespace sol { { "insert", &real_insert_call }, { "clear", &real_clear_call }, { "find", &real_find_call }, - { "erase", &real_erase_call } + { "erase", &real_erase_call }, + { "pairs", &pairs_call }, + { "next", &next_call }, }; - auto maybename = stack::check_get(L, 2); - if (maybename) { - const std::string& name = *maybename; + auto maybenameview = stack::check_get(L, 2); + if (maybenameview) { + const string_view& nameview = *maybenameview; +#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH + auto it = calls.find(nameview, string_view_hash(), std::equal_to()); +#else + std::string name(nameview.data(), nameview.size()); auto it = calls.find(name); +#endif if (it != calls.cend()) { return stack::push(L, it->second); } @@ -16848,6 +16979,18 @@ namespace sol { return real_index_get_traits(container_detail::has_traits_index_get(), L); } + static int real_at_traits(std::true_type, lua_State* L) { + return traits::at(L); + } + + static int real_at_traits(std::false_type, lua_State* L) { + return default_traits::at(L); + } + + static int real_at_call(lua_State* L) { + return real_at_traits(container_detail::has_traits_at(), L); + } + static int real_get_traits(std::true_type, lua_State* L) { return traits::get(L); } @@ -16908,6 +17051,18 @@ namespace sol { return real_ipairs_traits(container_detail::has_traits_ipairs(), L); } + static int real_next_traits(std::true_type, lua_State* L) { + return traits::next(L); + } + + static int real_next_traits(std::false_type, lua_State* L) { + return default_traits::next(L); + } + + static int real_next_call(lua_State* L) { + return real_next_traits(container_detail::has_traits_next(), L); + } + static int real_size_traits(std::true_type, lua_State* L) { return traits::size(L); } @@ -17028,6 +17183,14 @@ namespace sol { return detail::typed_static_trampoline(L); } + static int next_call(lua_State* L) { + return detail::typed_static_trampoline(L); + } + + static int at_call(lua_State* L) { + return detail::typed_static_trampoline(L); + } + static int get_call(lua_State* L) { return detail::typed_static_trampoline(L); } @@ -17061,11 +17224,15 @@ namespace sol { std::remove_pointer_t>> meta_cumt; static const char* metakey = is_shim ? &usertype_traits>>::metatable()[0] : &usertype_traits::metatable()[0]; - static const std::array reg = { { { "__pairs", &meta_cumt::pairs_call }, + static const std::array reg = { { + { "__pairs", &meta_cumt::pairs_call }, { "__ipairs", &meta_cumt::ipairs_call }, { "__len", &meta_cumt::length_call }, { "__index", &meta_cumt::index_call }, { "__newindex", &meta_cumt::new_index_call }, + { "pairs", &meta_cumt::pairs_call }, + { "next", &meta_cumt::next_call }, + { "at", &meta_cumt::at_call }, { "get", &meta_cumt::get_call }, { "set", &meta_cumt::set_call }, { "size", &meta_cumt::length_call }, @@ -17076,7 +17243,8 @@ namespace sol { { "find", &meta_cumt::find_call }, { "erase", &meta_cumt::erase_call }, std::is_pointer::value ? luaL_Reg{ nullptr, nullptr } : luaL_Reg{ "__gc", &detail::usertype_alloc_destruct }, - { nullptr, nullptr } } }; + { nullptr, nullptr } + } }; if (luaL_newmetatable(L, metakey) == 1) { luaL_setfuncs(L, reg.data(), 0); @@ -17436,25 +17604,8 @@ namespace sol { #include #include -#ifdef SOL_USE_BOOST -#include -#endif // Using Boost - namespace sol { namespace usertype_detail { -#if defined(SOL_USE_BOOST) -#if defined(SOL_CXX17_FEATURES) - template , typename E = std::equal_to<>> - using map_t = boost::unordered_map; -#else - template , typename E = std::equal_to<>> - using map_t = boost::unordered_map; -#endif // C++17 or not, WITH boost -#else - template , typename E = std::equal_to<>> - using map_t = std::unordered_map; -#endif // Boost map target - const int metatable_index = 2; const int metatable_core_index = 3; const int filler_index = 4; diff --git a/single/sol/sol_forward.hpp b/single/sol/sol_forward.hpp index 66b4957e..4ecdac15 100644 --- a/single/sol/sol_forward.hpp +++ b/single/sol/sol_forward.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2018-03-10 04:31:27.093885 UTC -// This header was generated with sol v2.19.5 (revision 623a38e) +// Generated 2018-03-11 01:45:35.146803 UTC +// This header was generated with sol v2.19.5 (revision a83091c) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP