 | SWIG allows us to add class methods
|
 | Calling message with standard output (std::cout) is tricky from Python so we add a print method for printing to std.output
|
 | print coincides with Python's keyword print so we follow the convention of adding an underscore:
%extend HelloWorld {
void print_() { self->message(std::cout); }
}
|
 | This is basically C++ syntax, but self is used instead of this and \%extend HelloWorld is a SWIG directive
|
 | Make extension module:
swig -python -c++ -I.. hw.i
# compile HelloWorld.cpp HelloWorld2.cpp hw_wrap.cxx
# link HelloWorld.o HelloWorld2.o hw_wrap.o to _hw.so
|