pybind11: Bind static constexpr

Viewed 168

So I have this header file with this in it

namespace lib {
    static constexpr int ERR_FAIL = 1;
}

I've tried to just bind it using def although I'm not surprised its not working since its not a function, but I when I tried to find how to do this in the documentation, I couldn't anything that would help me here.

Below is my attempt to bind this.

using namespace lib;

PYBIND11_MODULE(example, m){
    m.def("ERR_FAIL", &ERR_FAIL);
}

Would would be the best way to tackle this? I am aware that one option would be to use a lambda function, but is there a more direct way of exposing the constant to python, such that the the python syntax would look like this:

import example
print(example.ERR_FAIL)

>>1
0 Answers
Related