CreateWrapper

From PyWiki

Jump to: navigation, search

Contents

Creating a new wrapper

Here's how we wrap ParticleUniverse.. Obviously I tested it first with the Ogre C++ library to ensure everything works and to understand what is required to be wrapped/exposed.

Setup the Code Generation

Before we start we note that there is only one header file needed ParticleUniverseSystemManager.h and the library uses it's own namespace ParticleUniverse.. The single header file just makes life easier, both from an initial wrapping but also from a longer term manageability. Having a unique namespace makes life MUCH easier..

cd python-ogre/code_generators
xcopy template particleuniverse
cd particleuniverse
ren python_PROJECT.h python_particleuniverse.h
ren python_PROJECT_aliases.h python_particleuniverse_aliases.h
ren python_PROJECT_sizeof.h python_particleuniverse_sizeof.h

The Master Header File

edit python_particleuniverse.h

  • change PROJECT MASTER.h to your master include file
  • change _PROJECT to your project name and namespace

Note -- keep the project name in all lowercase, and the directory it lives in. It now looks like...

// keep everything in lowercase (except the namespace which must match the C++ library) to stop Linux/Windows issues
#include "ParticleUniverseSystemManager.h"  // the master include for the c++ library
 
// First we create a magic namespace to hold all our aliases
namespace pyplusplus { namespace aliases {
 
 #include "python_particleuniverse_aliases.h"   // we use this to fix up what would otherwise be ugly names
} } 
 
// then we exposed everything needed (and more) to ensure GCCXML makes them visible to Py++
//
namespace python_particleuniverse{ namespace details{
inline void instantiate(){
 using namespace ParticleUniverse;              // note the use of the 'actual' namespace here -- case sensitive
 #include "python_particleuniverse_sizeof.h"    // this is used to expose classes/variables that don't happen automatically
 
} } }

customization_data.py

edit customization_data.py to include the master header file

def header_files( version ):
    return [ "ParticleUniverseSystemManager.h"]
 
def huge_classes( version ):
    return []

generate_code.py

Now for the main generator file.. Edit generate_code.py Fix the main name space entry

from common_utils import docit
 
MAIN_NAMESPACE = 'ParticleUniverse'

Do a case sensitive search and replace -- change PROJECT to your projectname, in this case particleuniverse

And don't forget that you will probably have to define some symbols etc to pass to gcc to help.. A typical entry for a library that uses OGRE will be

defined_symbols = [ 'OGRE_NONCLIENT_BUILD', 'OGRE_GCC_VISIBILITY' ]

Edit the Configuration files

There are 2 main configuration files that need to now be edited - both are in the python-ogre top directory

environment.py

A new class must be created here for our new module

class particleuniverse:
    version="0.4"
    parent="ogre/addons"
    CCFLAGS = ' ' 
    cflags=""
    include_dirs = [ Config.PATH_Boost,
                    Config.PATH_INCLUDE_Ogre,
                    Config.PATH_INCLUDE_particleuniverse
                    ]
    lib_dirs = [Config.PATH_LIB_Boost,
                Config.PATH_LIB_Ogre_OgreMain,
                Config.PATH_LIB_particleuniverse
                ]
    CheckIncludes=[]
    libs=[  Config.LIB_Boost, 'OgreMain', 'ParticleUniverse' ]
    ModuleName="particleuniverse"   
    active=True

and don't forget to update the master class list (also in environment.py)

## Here is the master list....
## Keep eveything here in lowercase so the over rides work :)
 
projects = {
    'ois' : ois
    , 'ogre' : ogre
    , 'cegui' : cegui
    , 'ode' : ode
#     , 'newton' : newton
    , 'ogrerefapp' : ogrerefapp
    , 'ogrenewt' : ogrenewt
    , 'ogreode' : ogreode
    , 'ogreal' : ogreal
    , 'quickgui' : quickgui
    , 'opcode' : opcode
    , 'nxogre' : nxogre
    , 'bullet' : bullet
    , 'physx' : physx
    , 'betagui': betagui
    , 'theora' : theora
    , 'ogrevideoffmpeg' : ogrevideoffmpeg
    , 'ogredshow' : ogredshow
    , 'plib' : plib
    , 'navi': navi
    , 'ogrebulletc' : ogrebulletc
    , 'ogrebulletd' : ogrebulletd
    , 'ogreforests' : ogreforests
    , 'et' : et
    , 'caelum' : caelum
    , 'noise' : noise
    , 'watermesh' : watermesh
    , 'ofusion' : ofusion
    , 'particleuniverse' : particleuniverse
}

PythonOgreConfig_nt.py and PythonOgreConfig_posix.py

These files contain the actual locations for the various c++ libraries

PATH_particleuniverse = os.path.join(PATH_Ogre, 'PlugIns', 'ParticleUniverse' )
..
..
PATH_LIB_particleuniverse =     os.path.join(PATH_particleuniverse, 'bin', 'release')
..
..
PATH_INCLUDE_particleuniverse = os.path.join(PATH_particleuniverse, 'include' )

generate code

Head back to the code_generator directory and create some code

cd code_generators/particleuniverse
python generate_code.py >build.out 2>$1

And now the fun really starts while you work out what to fix/change/exclude based upon the particular library you are wrapping..

installing etc

You will need to edit setup.py to add the new module to it as well as create the __init__.py in the packages2.5\ogre\xxx directory. And don't forget the demos -- you need to create a new demo directory for each module and place any specific media files in that demo directory..

Personal tools