Jump to content
  • Advertisement
Sign in to follow this  

Jython/C++ OR CPython/C++?

This topic is 3715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently looking into gaining a scripting possibility with my C++ written Game engine (or SDK), and i'm not sure on the scripting platform. I've decided that python is the way to go, and i have to options: one is to use Boost::Python with CPython, and the other is to use JNI to get my C++ classes to use with Jython. I know that with Boost::Python i can't really use templates (well i can define all my types beforehand but it's very limited), and i'm not sure whether i can use JNI to get templates from C++ into Jython, anyone knows? another question is how does pickle cope with Boost::Python exported C++ classes? can it (un/)serialize them directly from python? and what about pickle with JNI exported classes? and how does the two compare performance wise? thanks for the help!

Share this post


Link to post
Share on other sites
Advertisement
C++ does not have run-time templates. Compiled C++ executable doesn't even have templated classes, they are all fully specialized.

So no matter which way you go, the classes you can pass to/from C++ will always be concrete.

Share this post


Link to post
Share on other sites
I personally find working with JNI to be a painful experience and don't recommend its use when you have a choice. boost::python exported classes work with pickling in basically the same way that Python classes with pickle support work by supplying definitions for __getinitargs__, __getstate__ and __setstate__. More details (and examples) can be found on the boost::python page on pickling.

Share this post


Link to post
Share on other sites
Boost.Python is nice, but there's some flaws. Py++, the automatic generator, uses GCCXML behind the scenes. GCCXML is a hack of the gcc compiler, designed to generate XML instead of object files. However, it doesn't support everything that GCC supports. Also, the bit about actually taking the full step of compiling is overkill for most things, so it runs a lot slower than it has to, when generating bindings. Furthermore, you'll find some code that GCCXML can't handle, moreso if you tend to work in a Visual C++ environment and then use GCCXML. It's very difficult to get Py++ with GCCXML to work in a Visual Studio environment.

I like Boost.Python, but it has the disadvantage of only binding to one language (Python) and making very large dlls. The framework is nice, but I felt that with the flaws of GCCXML (I really can't blame Py++ for this), that there was too much manual labor involved. If I could do it again, I would use SWIG, since with SWIG, you get upwards of 18 different languages automatically generated and the manual labor seems much lower.

Side note: Boost will support Luabind in 1.35; I don't know how compatible the Boost.Python and Boost.LuaBind code will be, but if they can be generated the same, there may be a benefit there.

Side-side note: If you ever delve into the Python-C API, you will see a pretty unfriendly API. That's the reason why entities like Boost.Python or SWIG are essential for binding to Python. I haven't done enough with JNI to make a fair comparison, but I would venture to suspect that the Python-C API is even more painful than JNI. I have heard rumors that the Ruby C API is relatively straightforward in comparison to the Python C API.

Share this post


Link to post
Share on other sites
If GCC is available to you, their CNI may be a useful interface. Basically it compiles Java code as any other supported language, then generates a set of headers so you can use it as if it was C++ code.

Share this post


Link to post
Share on other sites
Also try out the CTypes, a new feature to Python 2.5. It's supposed to be pretty nice. I haven't had a chance to check it out, but I'm hopeful for it.

Share this post


Link to post
Share on other sites
I believe Jython is at least a couple of versions behind CPython, (2.2 vs 2.5 ) so that could be an issue. Or at least the last time I checked, Jython was lagging behind.

Share this post


Link to post
Share on other sites
thanks for the help.
I think i'm going with SWIG, i like it better than boost, and i can make more bindings to other popular languages beside python with is very cool.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!