[C++-sig] Converting a C++ object to python
Ron Penton
rpenton at adelphia.net
Sun Sep 14 08:40:02 CEST 2003
This has been asked many times, in many variants, but I cannot seem to get this working in any shape or form, which leads me to believe I'm doing something numbskulled.
I'm trying to perform this sequence of events:
1 create a C++ object
2 convert it into a python object
3 pass it into python as a parameter to a function
Part 2 is the part that is holding me up. Observe:
class booga
{
public:
booga() : a( 0 ) {}
int a;
void looga() { a = a + 10; cout << a << endl; }
};
BOOST_PYTHON_MODULE( wrap )
{
class_<booga>( "booga" )
.def( "looga", &booga::looga );
}
int main()
{
Py_Initialize();
PyImport_AppendInittab( "wrap", initwrap );
booga b;
object obj( &b );
That last line of code always throws an exception of type error_already_set, from within the function "value_arg_to_python".
My thoughts are that I am missing something about a custom converter, or similar, but I've read through the converter docs and I'm quite baffled; they don't explain much. Would the BOOST_PYTHON_MODULE create a custom converter for classes in there, or must I specify one manually, or what?
I apologize if this is too simple of a problem, in advance =)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030914/45118e81/attachment.htm>
More information about the Cplusplus-sig
mailing list