It appears there are declaration order problems in the generated code. It could be related to the version of pybind11 I used (2.2.0) or compiler version (msvc2015). But these errors can be fixed with a few simple changes.
There were 3 lines which gave an error while importing the python module: ImportError: arg(): could not convert default argument into a Python object (type not registered yet?). Compile in debug mode for more information.
.def("isVisible", &BulletInterface::isVisible, py::arg("player") = (Player) nullptr)
It is referring to Player in the default paramter but it has not been registered yet. This one I fixed by naming the PlayerInterface wrapper definition and moving up above the BulletInterface:
py::class_<BWAPI::PlayerInterface, std::unique_ptr<BWAPI::PlayerInterface, py::nodelete>> player(m, "Player");
py::class_<BWAPI::BulletInterface, std::unique_ptr<BWAPI::BulletInterface, py::nodelete>>(m, "Bullet")
...
.def("isVisible", &BulletInterface::isVisible, py::arg("player") = (Player) nullptr)
...
player
.def("getID", &PlayerInterface::getID)
The next 2 problems are in the UnitInterface wrapper. The default parameters cast nullptr to Unit, but Unit has not been registered yet.
.def("useTech", (bool (UnitInterface::*)(TechType, Unit)) &UnitInterface::useTech, py::arg("tech"), py::arg("target") = (Unit) nullptr)
.def("canUseTech", (bool (UnitInterface::*)(TechType, Unit, bool, bool, bool, bool) const) &UnitInterface::canUseTech, py::arg("tech"), py::arg("target") = (Unit) nullptr, py::arg("checkCanTargetUnit") = true, py::arg("checkTargetsType") = true, py::arg("checkCanIssueCommandType") = true, py::arg("checkCommandibility") = true)
These I fixed by naming the class again, changing the first 2 lines to:
py::class_<BWAPI::UnitInterface, std::unique_ptr<BWAPI::UnitInterface, py::nodelete>> unit(m, "Unit");
unit
.def("getID", &UnitInterface::getID)
After making these changes, I was able to import the python module without errors.
It appears there are declaration order problems in the generated code. It could be related to the version of pybind11 I used (2.2.0) or compiler version (msvc2015). But these errors can be fixed with a few simple changes.
There were 3 lines which gave an error while importing the python module:
ImportError: arg(): could not convert default argument into a Python object (type not registered yet?). Compile in debug mode for more information.It is referring to
Playerin the default paramter but it has not been registered yet. This one I fixed by naming the PlayerInterface wrapper definition and moving up above the BulletInterface:The next 2 problems are in the UnitInterface wrapper. The default parameters cast
nullptrtoUnit, butUnithas not been registered yet.These I fixed by naming the class again, changing the first 2 lines to:
After making these changes, I was able to import the python module without errors.