Export existing enums


#1

There is an open issue about creating enums directly in Chaiscript, but is there a way to export existing C++ enum types (or even better enum class types) to Chaiscript?


#2

You can export the individual values with no problem:

This should work equally well for enum or enum class.

To properly implement this we need to have namespace support of some type, which is currently being pondered, but has no implementation.


#3

I know this is an old topic, but I thought I’d share that class enums work well for me with the following lambdas:

chai.add_global_const(chaiscript::const_var(Test_enumeration::value3),"value3");
chai.add_global_const(chaiscript::const_var(Test_enumeration::value2),"value2");
chai.add(chaiscript::fun([](const Test_enumeration lhs,const Test_enumeration rhs) {return (lhs==rhs); }),"==");
chai.add(chaiscript::fun([](Test_enumeration& lhs,const Test_enumeration rhs) {return (lhs=rhs); }),"=");

#4

I should mention also that there is now an enum class helper that you can see the use / test of here: