Export existing enums

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?

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.

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(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); }),"=");

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

1 Like