tiled
tiled copied to clipboard
Modernize Python bindings
The current Python plugin relies on a large amount of generated code based on the somewhat hard to maintain and always incomplete tiledbinding.py
and qtbinding.py
.
I've recently learned about pybind11 (see also this blog post), which seems like a much nicer way of binding the classes to Python. The bindings are defined with similar verbosity, but directly in C++ which makes it easier to keep up-to-date.
In addition, pybind11 provides a more convenient way of interfacing with an embedded Python interpreter than using the Python API directly.
Did You consider using boost::python?
Sample binding looks like this:
class_<CGame, bases<CGameObject>, boost::noncopyable, std::shared_ptr<CGame>>("CGame", no_init)
.def("getMap", &CGame::getMap)
.def("changeMap", &CGame::changeMap)
.def("loadPlugin", &CGame::loadPlugin)
.def("getGuiHandler", &CGame::getGuiHandler)
.def("getObjectHandler", &CGame::getObjectHandler)
.def("createObject", &CGame::createObject<CGameObject>)
.def("getGui", &CGame::getGui);
and python:
@register(context)
class ChangeMap(CEvent):
def onEnter(self, event):
self.getMap().getGame().changeMap("map2")
@lisu188 I didn't try either yet, but the README.md
from pybind11 has a lot to say about Boost.Python, and it makes pybind11 sound rather more attractive.
In the context of this issue, also try using binder for even more automatic binding generation.