Re: [C++-sig] problem w/intermodule communication

2008-11-25 Thread William Ladwig
Neal,

Try adding:

register_ptr_to_python< boost::shared_ptr >();

to your BOOST_PYTHON_MODULE(test2) section.

Hope this helps,

Bill


From: [EMAIL PROTECTED] [EMAIL PROTECTED] On Behalf Of Neal Becker [EMAIL 
PROTECTED]
Sent: Monday, November 24, 2008 6:15 PM
To: [email protected]
Subject: [C++-sig] problem w/intermodule communication

Here is a simple example.

---
test1.cc

#include 
#include 
#include 
#include 

using namespace boost::python;

struct A {
  A (int _x) : x (_x) {}
  int x;
};

BOOST_PYTHON_MODULE(test1) {
  class_ ("A", init());
}
--

test2.cc

#include 
#include 
#include 
#include 
#include 

using namespace boost::python;

struct A {
  A (int _x) : x (_x) {}
  int x;
};

struct B {
  B (boost::shared_ptr _a) : a (_a) {}
  boost::shared_ptr a;
};

BOOST_PYTHON_MODULE(test2) {
  class_ ("B", init >())
.def_readonly ("a", &B::a)
 ;
}
-

test12.py

from test1 import A
from test2 import B

a = A(1)
b = B(a)

print b.a
-

TypeError: No to_python (by-value) converter found for C++ type: 
boost::shared_ptr

How can I solve this?  Now consider:


test3.cc

#include 
#include 
#include 
#include 

using namespace boost::python;

struct A {
  A (int _x) : x (_x) {}
  int x;
};

struct B {
  B (boost::shared_ptr _a) : a (_a) {}
  boost::shared_ptr a;
};

BOOST_PYTHON_MODULE(test3) {
  class_ ("A", init());

  class_ ("B", init >())
.def_readonly ("a", &B::a)
 ;
}

-

test13.py

from test3 import A, B

a = A(1)
b = B(a)

print b.a
---


So if both are in same module, no problem.  If they are in different modules it 
doesn't work.  Any ideas?

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] problem w/intermodule communication

2008-11-25 Thread Neal Becker
William Ladwig wrote:

> Neal,
> 
> Try adding:
> 
> register_ptr_to_python< boost::shared_ptr >();
> 
> to your BOOST_PYTHON_MODULE(test2) section.
> 
> Hope this helps,
> 
> Bill
> 

Thanks!  That's what it needed.

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig