diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 87ae9801..8343d95b 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 2016-08-24 16:24:16.873107 UTC -// This header was generated with sol v2.12.0 (revision 16cd699) +// Generated 2016-08-25 16:51:18.743349 UTC +// This header was generated with sol v2.12.1 (revision 354c267) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -590,37 +590,54 @@ namespace sol { static const bool value = sizeof(test(0)) == sizeof(yes); }; + struct has_begin_end_impl { + template, + typename B = decltype(std::declval().begin()), + typename E = decltype(std::declval().end())> + static std::true_type test(int); + + template + static std::false_type test(...); + }; + + struct has_key_value_pair_impl { + template, + typename V = typename U::value_type, + typename F = decltype(std::declval().first), + typename S = decltype(std::declval().second)> + static std::true_type test(int); + + template + static std::false_type test(...); + }; + + template () < std::declval())> + std::true_type supports_op_less_test(const T&); + std::false_type supports_op_less_test(...); + template () == std::declval())> + std::true_type supports_op_equal_test(const T&); + std::false_type supports_op_equal_test(...); + template () <= std::declval())> + std::true_type supports_op_less_equal_test(const T&); + std::false_type supports_op_less_equal_test(...); + } // meta_detail + template + using supports_op_less = decltype(meta_detail::supports_op_less_test(std::declval())); + template + using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::declval())); + template + using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::declval())); + template struct is_callable : boolean::value> {}; - struct has_begin_end_impl { - template, - typename B = decltype(std::declval().begin()), - typename E = decltype(std::declval().end())> - static std::true_type test(int); - - template - static std::false_type test(...); - }; + template + struct has_begin_end : decltype(meta_detail::has_begin_end_impl::test(0)) {}; template - struct has_begin_end : decltype(has_begin_end_impl::test(0)) {}; - - struct has_key_value_pair_impl { - template, - typename V = typename U::value_type, - typename F = decltype(std::declval().first), - typename S = decltype(std::declval().second)> - static std::true_type test(int); - - template - static std::false_type test(...); - }; - - template - struct has_key_value_pair : decltype(has_key_value_pair_impl::test(0)) {}; + struct has_key_value_pair : decltype(meta_detail::has_key_value_pair_impl::test(0)) {}; template using is_string_constructible = any, const char*>, std::is_same, char>, std::is_same, std::string>, std::is_same, std::initializer_list>>; @@ -9353,8 +9370,14 @@ namespace sol { // end of sol/deprecate.hpp namespace sol { - namespace usertype_detail { + struct no_comp { + template + bool operator()(A&&, B&&) { + return false; + } + }; + inline bool is_indexer(string_detail::string_shim s) { return s == name_of(meta_function::index) || s == name_of(meta_function::new_index); } @@ -9408,6 +9431,37 @@ namespace sol { return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data()); } + template + inline int operator_wrap(lua_State* L) { + auto maybel = stack::check_get(L, 1); + if (maybel) { + auto mayber = stack::check_get(L, 2); + if (mayber) { + auto& l = *maybel; + auto& r = *mayber; + if (std::is_same::value) { + return stack::push(L, detail::ptr(l) == detail::ptr(r)); + } + else { + Op op; + return stack::push(L, (detail::ptr(l) == detail::ptr(r)) || op(detail::deref(l), detail::deref(r))); + } + } + } + return stack::push(L, false); + } + + template = meta::enabler> + inline void make_reg_op(Regs& l, int& index, const char* name) { + l[index] = { name, &operator_wrap }; + ++index; + } + + template = meta::enabler> + inline void make_reg_op(Regs&, int&, const char*) { + // Do nothing if there's no support + } + struct add_destructor_tag {}; struct check_destructor_tag {}; struct verified_tag {} const verified{}; @@ -9456,7 +9510,7 @@ namespace sol { struct usertype_metatable, Tn...> : usertype_detail::registrar { typedef std::make_index_sequence indices; typedef std::index_sequence half_indices; - typedef std::array regs_t; + typedef std::array regs_t; typedef std::tuple RawTuple; typedef std::tuple ...> Tuple; template @@ -9475,6 +9529,9 @@ namespace sol { void* baseclasscast; bool mustindex; bool secondarymeta; + bool hasequals; + bool hasless; + bool haslessequals; template >> = meta::enabler> inline lua_CFunction make_func() { @@ -9498,6 +9555,18 @@ namespace sol { } int finish_regs(regs_t& l, int& index) { + if (!hasless) { + const char* name = name_of(meta_function::less_than).c_str(); + usertype_detail::make_reg_op, meta::supports_op_less>(l, index, name); + } + if (!haslessequals) { + const char* name = name_of(meta_function::less_than_or_equal_to).c_str(); + usertype_detail::make_reg_op, meta::supports_op_less_equal>(l, index, name); + } + if (!hasequals) { + const char* name = name_of(meta_function::equal_to).c_str(); + usertype_detail::make_reg_op::value, std::equal_to<>, usertype_detail::no_comp>, std::true_type>(l, index, name); + } if (destructfunc != nullptr) { l[index] = { name_of(meta_function::garbage_collect).c_str(), destructfunc }; ++index; @@ -9536,6 +9605,15 @@ namespace sol { // Returnable scope // That would be a neat keyword for C++ // returnable { ... }; + if (reg.name == name_of(meta_function::equal_to)) { + hasequals = true; + } + if (reg.name == name_of(meta_function::less_than)) { + hasless = true; + } + if (reg.name == name_of(meta_function::less_than_or_equal_to)) { + haslessequals = true; + } if (reg.name == name_of(meta_function::garbage_collect)) { destructfunc = reg.func; return; @@ -9561,7 +9639,8 @@ namespace sol { indexbase(&core_indexing_call), newindexbase(&core_indexing_call), indexbaseclasspropogation(walk_all_bases), newindexbaseclasspropogation(walk_all_bases), baseclasscheck(nullptr), baseclasscast(nullptr), - mustindex(contains_variable() || contains_index()), secondarymeta(contains_variable()) { + mustindex(contains_variable() || contains_index()), secondarymeta(contains_variable()), + hasequals(false), hasless(false), haslessequals(false) { } template @@ -9734,9 +9813,9 @@ namespace sol { (void)detail::swallow{ 0, (um.template make_regs<(I * 2)>(value_table, lastreg, std::get<(I * 2)>(um.functions), std::get<(I * 2 + 1)>(um.functions)), 0)... }; um.finish_regs(value_table, lastreg); value_table[lastreg] = { nullptr, nullptr }; - bool hasdestructor = !value_table.empty() && name_of(meta_function::garbage_collect) == value_table[lastreg - 1].name; regs_t ref_table = value_table; regs_t unique_table = value_table; + bool hasdestructor = !value_table.empty() && name_of(meta_function::garbage_collect) == value_table[lastreg - 1].name; if (hasdestructor) { ref_table[lastreg - 1] = { nullptr, nullptr }; unique_table[lastreg - 1] = { value_table[lastreg - 1].name, detail::unique_destruct }; @@ -9909,6 +9988,9 @@ namespace sol { typedef simple_usertype_metatable umt_t; static int push(lua_State* L, umt_t&& umx) { + bool hasequals = false; + bool hasless = false; + bool haslessequals = false; for (std::size_t i = 0; i < 3; ++i) { // Pointer types, AKA "references" from C++ const char* metakey = nullptr; @@ -9927,25 +10009,53 @@ namespace sol { luaL_newmetatable(L, metakey); stack_reference t(L, -1); for (auto& kvp : umx.registrations) { - switch (i) { - case 0: - if (kvp.first.template is() && kvp.first.template as() == "__gc") { - continue; + if (kvp.first.template is()) { + std::string regname = kvp.first.template as(); + if (regname == name_of(meta_function::equal_to)) { + hasequals = true; } - break; - case 1: - if (kvp.first.template is() && kvp.first.template as() == "__gc") { - stack::set_field(L, kvp.first, detail::unique_destruct, t.stack_index()); - continue; + else if (regname == name_of(meta_function::less_than)) { + hasless = true; + } + else if (regname == name_of(meta_function::less_than_or_equal_to)) { + haslessequals = true; + } + switch (i) { + case 0: + if (regname == name_of(meta_function::garbage_collect)) { + continue; + } + break; + case 1: + if (regname == name_of(meta_function::garbage_collect)) { + stack::set_field(L, kvp.first, detail::unique_destruct, t.stack_index()); + continue; + } + break; + case 2: + default: + break; } - break; - case 2: - default: - break; } stack::set_field(L, kvp.first, kvp.second, t.stack_index()); } - + luaL_Reg opregs[4]{}; + int opregsindex = 0; + if (!hasless) { + const char* name = name_of(meta_function::less_than).c_str(); + usertype_detail::make_reg_op, meta::supports_op_less>(opregs, opregsindex, name); + } + if (!haslessequals) { + const char* name = name_of(meta_function::less_than_or_equal_to).c_str(); + usertype_detail::make_reg_op, meta::supports_op_less_equal>(opregs, opregsindex, name); + } + if (!hasequals) { + const char* name = name_of(meta_function::equal_to).c_str(); + usertype_detail::make_reg_op::value, std::equal_to<>, usertype_detail::no_comp>, std::true_type>(opregs, opregsindex, name); + } + t.push(); + luaL_setfuncs(L, opregs, 0); + t.pop(); // Metatable indexes itself stack::set_field(L, meta_function::index, t, t.stack_index()); @@ -10015,17 +10125,17 @@ namespace sol { } - template + template struct container_usertype_metatable { - typedef meta::unqualified_t U; + typedef meta::unqualified_t T; typedef std::size_t K; - typedef typename U::value_type V; - typedef typename U::iterator I; + typedef typename T::value_type V; + typedef typename T::iterator I; struct iter { - U& source; + T& source; I it; - iter(U& source, I it) : source(source), it(std::move(it)) {} + iter(T& source, I it) : source(source), it(std::move(it)) {} }; static auto& get_src(lua_State* L) { @@ -10172,18 +10282,18 @@ namespace sol { } }; - template - struct container_usertype_metatable::value>> { - typedef meta::unqualified_t U; - typedef typename U::value_type KV; + template + struct container_usertype_metatable>::value>> { + typedef meta::unqualified_t T; + typedef typename T::value_type KV; typedef typename KV::first_type K; typedef typename KV::second_type V; - typedef typename U::iterator I; + typedef typename T::iterator I; struct iter { - U& source; + T& source; I it; - iter(U& source, I it) : source(source), it(std::move(it)) {} + iter(T& source, I it) : source(source), it(std::move(it)) {} }; static auto& get_src(lua_State* L) {