OOF2: The Manual
OOF2 uses an old (but stable) version of swig, version 1.1 build 883. These instructions will have to be modified when we move to a later version. There's no fundamental reason that an OOF2 extension can't use a different version of swig, but it'll probably make things a lot harder.
The following sample swig file contains examples of most of the useful constructs. The annotations explain which lines are necessary, and when.
#ifndef EXTENSION_SWG#define EXTENSION_SWG %module extension
%{ #include "myextension.h"
%} %include "common/typemaps.swg"
%pragma(python) include="myextension.spy"
%pragma(python) code="from SWIGdir.othermodule import MyBasePtr"
%extern "othermodule.swg"
class MyExtension : public MyBase {
public: MyExtension();
}; #endif // EXTENSION_SWG
Defining and checking |
|
This line is recommended, but not required. Replace
|
|
Any code within |
|
This line must be included in every
OOF2 swig file to ensure that exceptions are handled
correctly. |
|
This line appends the given file to
swig's Python output. The file
can contain Python code that modifies the classes produced
by swig, or performs other
initialization tasks. This is just a convenient place to
perform such tasks — if there are no tasks, then
this line (and the file) can be omitted. The
|
|
If the swigged class is derived from a base class that was
swigged elsewhere, then two things are necessary: the Python
code that swig generates must
import the base class, and swig
must be told about the base class.[46]
This line imports the base class into the swig python
output.
Note that the imported name has |
|
An |
|
All swigged base classes of the swigged class need to appear here. Base classes that are not swigged should not be listed. |
|
All member functions that will be used in Python need to be
listed here. Swig typemaps, such as those in
|
[46]
Note that when swigging a new OOF2
Property
, both of these tasks are
handled by engine/propertyhdr.swg
.