How to use user defined ENUM


#1

I am having issue assigning an enum value in chai on an object, I keep getting error when running script Error with function dispatch for function ‘Value1’ With parameters: (Function).(string). Example code below: I have added the test class user chaiscript::utility::add_class

    enum TestEnum
    {
         Value1;
    };

    class TestClass
    {
    public:
        TestEnum testEnum;
    };

    
   chai.add_global_const(chaiscript::const_var(TestEnum::Value1),"value1");
   chai.add(chaiscript::fun([](const TestEnum lhs,const TestEnum rhs) {return (lhs==rhs); }),"==");
   chai.add(chaiscript::fun([](TestEnum& lhs,const TestEnum rhs) {return (lhs=rhs); }),"=");

ChaiScript:

  var testClass = TestClass;
  testClass.testEnum = Value1;

#2

This was my mistake, I was not constructing the class object correctly: The fix was

 var testClass = TestClass();
 testClass.testEnum = Value1;