Python for logic, C for backend

Started by
5 comments, last by Sneftel 14 years, 4 months ago
I'm interested in writing an engine where all the rendering and other engine type things are done in C and the game(s) would be written in Python. So, I'm wondering, would this be done best by wrapping a C DLL with ctypes or by writing Python plugin, or something else?
Advertisement
Boost.Python would be worth checking out...
Quote:Original post by Uphoreum
I'm interested in writing an engine where all the rendering and other engine type things are done in C and the game(s) would be written in Python. So, I'm wondering, would this be done best by wrapping a C DLL with ctypes or by writing Python plugin, or something else?
There are a lot of solutions to this, and they all come with tradeoffs - here are a few popular options:
  • ctypes is probably the simplest, as it just requires minimal python wrapper code, but it is also by far the slowest to make function calls into C, and it isn't trivial to call Python from the C code.

  • boost::python is the most flexible solution for C++, and is pretty efficient, although the compiler and library setup can be a bit of a pain across multiple platforms.

  • SWIG lets you bind C/C++ to all sorts of languages (including Python), and generates fairly efficient wrappers, but requires pages of SWIG 'glue' to bind the C/C++ API.

  • Pyrex et al. allows you to write python extension modules in a hybrid python/C dialect, and produces efficient code, but can be problematic to interact with C++.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Cython is the successor to Pyrex and has slightly better C++ support. Worth a look.
This page: http://wiki.cython.org/WrappingCorCpp has a list of 10 different ways. I'm also interested in writing a c++ backend with python logic, but I've only just started looking into it so I can't offer more than this link.
If you're not hell-bent on writing your own graphics engine, why don't you check out an existing engine with python bindings.
Or, better yet, a game engine (not just a graphics engine) written from the ground up to be used to make games with Python.

This topic is closed to new replies.

Advertisement