Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for "Type not registered yet" error when importing from Python #4

Open
ratiotile opened this issue Sep 29, 2017 · 0 comments
Open

Comments

@ratiotile
Copy link

ratiotile commented Sep 29, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant