Add some operators for Enums made with helper class
This commit is contained in:
parent
e1c40f3e8f
commit
e32714c456
@ -15,6 +15,7 @@
|
||||
#include "../chaiscript.hpp"
|
||||
#include "../dispatchkit/proxy_functions.hpp"
|
||||
#include "../dispatchkit/type_info.hpp"
|
||||
#include "../dispatchkit/operators.hpp"
|
||||
|
||||
|
||||
namespace chaiscript
|
||||
@ -63,7 +64,7 @@ namespace chaiscript
|
||||
t_module.add(fun.first, fun.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename Enum, typename ModuleType>
|
||||
typename std::enable_if<std::is_enum<Enum>::value, void>::type
|
||||
add_class(ModuleType &t_module,
|
||||
@ -76,6 +77,12 @@ namespace chaiscript
|
||||
t_module.add(chaiscript::constructor<Enum ()>(), t_class_name);
|
||||
t_module.add(chaiscript::constructor<Enum (const Enum &)>(), t_class_name);
|
||||
|
||||
t_module.add([](){
|
||||
// add some comparison and assignment operators
|
||||
using namespace chaiscript::bootstrap::operators;
|
||||
return assign<Enum>(not_equal<Enum>(equal<Enum>()));
|
||||
}());
|
||||
|
||||
for (const auto &constant : t_constants)
|
||||
{
|
||||
t_module.add_global_const(constant.first, constant.second);
|
||||
|
@ -562,6 +562,11 @@ TEST_CASE("Utility_Test utility class wrapper for enum")
|
||||
CHECK_NOTHROW(chai.eval("do_something_with_enum_vector([ONE])"));
|
||||
CHECK_NOTHROW(chai.eval("[ONE]"));
|
||||
|
||||
CHECK(chai.eval<bool>("ONE == ONE"));
|
||||
CHECK(chai.eval<bool>("ONE != TWO"));
|
||||
CHECK_NOTHROW(chai.eval("var o = ONE; o = TWO"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user