beginner questions on embedding/extending python with C++

Diez B. Roggisch deets at nospam.web.de
Tue Aug 8 06:03:13 EDT 2006


> 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?

You should look into SIP besides the tools you already mentioned - IMHO it
is the best choice for wrapping C++.

And yes, you need to wrap classes - but only those that are of interest for
you! So if you need Player, wrap Player. No need to wrap it's base-classes,
unless you want these for other purposes, too.

And for global objects I'd create functions which return these.

I suggest you try and download a project that uses one of the possible
toolkits for wrapping - the most prominent user of SIP is of course PyQt.
Go and have a look at the source, how things are done. There aresome
tutorials I think, google should help you on that.

HTH Diez



More information about the Python-list mailing list