Add operator== and operator!= support for sol::object and nil

This commit is contained in:
Rapptz 2013-12-14 00:28:14 -05:00
parent a6306d7012
commit f061e0040d

View File

@ -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