Panda3D Manual: Interrogate
InterrogateInterrogate is a program to parse a body of C++ code and build up a table of classes, methods, functions, and symbols found, for the purposes of calling into the codebase via a non-C++ scripting language like Python (Scheme and Smalltalk were also tried at some point) The design of interrogate is such that it should be able to produce wrappers for any other language without too much trouble. You'll have to be responsible for writing and maintaining the interface layer to produce the wrappers, though. In addition to identifying all the classes and their relationships, interrogate will generate a wrapper function for each callable function. The wrapper functions will be callable directly from the scripting language, with no understanding of C++ necessary; these wrapper functions will in turn call the actual C++ functions or methods. Most exportable features of C++ are supported, including templates, default parameters, and function overloading. How to use itThere are a few steps involved in generating python wrappers using interrogate. Steps for Interrogate:
interrogate -oc test_igate.cxx -od test.in -python-native test.h
interrogate_module -oc test_module.cxx -python-native test.in
from libtest import TestClass
Calling InterrogateThis section will explain how to call interrogate and will briefly address the most important options. For the full documentation, however, refer to the interrogate help file (accessible by calling interrogate with the -h option). When calling interrogate, you will need to include the -oc and -od options, which specify where the generated code and function tables, respectively, will be written. The -module and -library options are used to specify the name of your module and library. These options are mainly code-organizational. You can omit both options. With -D you can ignore or make interrogate interpret symbols differently. For example, if your code uses a non-standard C macro like __inline, you would need to call interrogate with -D__inline. Or, if you would like certain defines to be defined differently, you can use -Ddefvar=value. Furthermore, there are a few special flags that you most likely want to include. There is the -string option, which treats the C++ char* and STL strings as special cases, and maps them to the scripting language's string equivalent, instead of a wrapper to basic_string<char>. The option -refcount makes the wrappers compatible with Panda3D's smart reference counting system, if your library depends on Panda3D you will want to include it too. The -assert option is just used for Python wrappers and specifies that when the C++ code throws an assert, this will be translated to an AssertionError exception in python. Wrapper functionsThere are three/four options that specify how to generate the wrapper functions:
You can also specify a combination of any of those. If all are omitted, the default is -c. Here's a small example: interrogate -D__inline -DCPPPARSER -D__cplusplus -S/usr/include/panda3d/parser-inc -S/usr/include/ -I/usr/include/panda3d/ -oc myModule_igate.cxx -od myModule.in -fnames -string -refcount -assert -python-native -module libMyModule -library libMyModule myModule.h interrogate_module -oc myModule_module.cxx -module libMyModule -library libMyModule -python-native myModule.in More Information
© Carnegie Mellon University 2010 |