mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Add operator== and operator!= support for sol::object and nil
This commit is contained in:
parent
a6306d7012
commit
f061e0040d
|
@ -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
|
Loading…
Reference in New Issue
Block a user