From f061e0040df7fb652f3c56f23e744673585bd2a7 Mon Sep 17 00:00:00 2001 From: Rapptz <rapptz@gmail.com> Date: Sat, 14 Dec 2013 00:28:14 -0500 Subject: [PATCH] Add operator== and operator!= support for sol::object and nil --- sol/object.hpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sol/object.hpp b/sol/object.hpp index db374fd2..1c6f53d1 100644 --- a/sol/object.hpp +++ b/sol/object.hpp @@ -32,20 +32,36 @@ public: object() = default; template<typename T> - T as() { + T as() const { push(); type_assert(state(), -1, type_of<T>()); return stack::get<T>(state()); } template<typename T> - bool is() { + bool is() const { push(); auto expected = type_of<T>(); auto actual = lua_type(state(), -1); return (static_cast<int>(expected) == actual) || (expected == type::poly); } }; + +bool operator==(const object& lhs, const nil_t&) { + return lhs.is<nil_t>(); +} + +bool operator==(const nil_t&, const object& rhs) { + return rhs.is<nil_t>(); +} + +bool operator!=(const object& lhs, const nil_t&) { + return !lhs.is<nil_t>(); +} + +bool operator!=(const nil_t&, const object& rhs) { + return !rhs.is<nil_t>(); +} } // sol #endif // SOL_OBJECT_HPP \ No newline at end of file