Fix comparisons done of improper types

This commit is contained in:
ThePhD 2016-10-30 04:40:17 -04:00
parent 76cae575e8
commit 0859af3203
3 changed files with 33 additions and 10 deletions

View File

@ -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-10-29 19:13:08.076162 UTC
// This header was generated with sol v2.14.12 (revision f896a9e)
// Generated 2016-10-30 08:39:55.311816 UTC
// This header was generated with sol v2.14.12 (revision 76cae57)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -9637,22 +9637,26 @@ namespace sol {
template<typename Table, typename Key, typename T>
inline bool operator==(T&& left, const proxy<Table, Key>& right) {
return left == right.template get<std::decay_t<T>>();
typedef decltype(stack::get<T>(nullptr, 0)) U;
return right.template get<optional<U>>() == left;
}
template<typename Table, typename Key, typename T>
inline bool operator==(const proxy<Table, Key>& right, T&& left) {
return right.template get<std::decay_t<T>>() == left;
typedef decltype(stack::get<T>(nullptr, 0)) U;
return right.template get<optional<U>>() == left;
}
template<typename Table, typename Key, typename T>
inline bool operator!=(T&& left, const proxy<Table, Key>& right) {
return right.template get<std::decay_t<T>>() != left;
typedef decltype(stack::get<T>(nullptr, 0)) U;
return right.template get<optional<U>>() == left;
}
template<typename Table, typename Key, typename T>
inline bool operator!=(const proxy<Table, Key>& right, T&& left) {
return right.template get<std::decay_t<T>>() != left;
typedef decltype(stack::get<T>(nullptr, 0)) U;
return right.template get<optional<U>>() == left;
}
template<typename Table, typename Key>

View File

@ -123,22 +123,26 @@ namespace sol {
template<typename Table, typename Key, typename T>
inline bool operator==(T&& left, const proxy<Table, Key>& right) {
return left == right.template get<std::decay_t<T>>();
typedef decltype(stack::get<T>(nullptr, 0)) U;
return right.template get<optional<U>>() == left;
}
template<typename Table, typename Key, typename T>
inline bool operator==(const proxy<Table, Key>& right, T&& left) {
return right.template get<std::decay_t<T>>() == left;
typedef decltype(stack::get<T>(nullptr, 0)) U;
return right.template get<optional<U>>() == left;
}
template<typename Table, typename Key, typename T>
inline bool operator!=(T&& left, const proxy<Table, Key>& right) {
return right.template get<std::decay_t<T>>() != left;
typedef decltype(stack::get<T>(nullptr, 0)) U;
return right.template get<optional<U>>() == left;
}
template<typename Table, typename Key, typename T>
inline bool operator!=(const proxy<Table, Key>& right, T&& left) {
return right.template get<std::decay_t<T>>() != left;
typedef decltype(stack::get<T>(nullptr, 0)) U;
return right.template get<optional<U>>() == left;
}
template<typename Table, typename Key>

View File

@ -664,6 +664,21 @@ TEST_CASE("proxy/proper-pushing", "allow proxies to reference other proxies and
REQUIRE(b);
}
TEST_CASE("proxy/equality", "check to make sure equality tests work") {
sol::state lua;
REQUIRE((lua["a"] == sol::nil));
REQUIRE_FALSE((lua["a"] == nullptr));
REQUIRE_FALSE((lua["a"] == 0));
REQUIRE_FALSE((lua["a"] == 2));
lua["a"] = 2;
REQUIRE_FALSE((lua["a"] == sol::nil)); //0
REQUIRE_FALSE((lua["a"] == nullptr)); //0
REQUIRE_FALSE((lua["a"] == 0)); //0
REQUIRE((lua["a"] == 2)); //1
}
TEST_CASE("compilation/const-regression", "make sure constness in tables is respected all the way down") {
struct State {
public: