beginner questions on embedding/extending python with C++

Qun Cao quncao at gmail.com
Tue Aug 8 05:28:31 EDT 2006


Hi Everyone,

I am a beginner on cross language development. My problem at hand is to
build a python interface for a C++ application built on top of a 3D
game engine.  The purpose of this python interface is providing a
convenient scripting toolkit for the application.  One example is that
a user can write a python script like:
	   player = Player()
	   game.loadPlayer(player)
	   player.moveTo(location)
To configure the game environment.

I am trying to figure out how to make this happen.  I only have the
vague idea that this concerns embedding/extending python with C++, but
after reading Python Doc, SWIG, BOOST.Python, I am still not sure how
to architecture it.

Since the main program is still going to be the C++ application, I
guess we need to embedding the python scripts in the C++ code.  So at
initialization stage, the python script needs to be loaded into the C++
code.  And this code can be simple, like
	player = Player()
	game.loadPlayer(player)


But for this to work, the python code needs to know the Player class,
is it right? Does that mean I need to build a python wrapper class for
Player and "import Player" in the python code?  But because this
application is built on top of a game engine, Player class inherits
many classes from there, I cannot possibly wrapping them all, right?
Also, some global objects are probably needed in this code of adding
players, how can the python code access them?

I know I probably don't have a grasp of basics here,  please kindly
enlighten me!

Btw, if you can point me to any source code of non-trivial projects
utilizing SWIG/Boost.Python, that would be very helpful.  I found the
examples on the tutorials are far too simple.

Thank you very much, 
Qun




More information about the Python-list mailing list