Re: [pygccxml-development] Exposing boost::python::list
Brought to you by:
mbaas,
roman_yakovenko
From: Scott S. <sc...@bi...> - 2011-08-02 20:32:04
|
As a follow on, I did get this to work by using an actual list, and not a pointer to one. So the pseudocode becomes: #pramga once #ifndef __GCCXML__ #include <boost/python.hpp> typedef boost::python::list list; #else class list {}; #endif class MyClass { public list mylist; MyClass() { mylist.append(1); } }; Then in python, I have no problems: >>> mc.mylist [1] >>> mc.append(2) >>> mc.mylist [1,2] Thanks, Scott On Mon, 1 Aug 2011, Scott Sturdivant wrote: > Hi, > > I'd like to have a class which as a boost::python::list as a public > attribute. I know that gccxml cannot parse boost/python.hpp, so given a > suggestion on the mailing list archives, I have done the following: > > #pragma once > #ifndef __GCCXML__ > #include <boost/python.hpp> > typedef boost::python::list list; > #else > class list; > #endif > > class MyClass { > public: > list * mylist; > }; > > MyClass::MyClass() > { > mylist = new boost::python::list(); > mylist.append(1); > } > MyClass::~MyClass() > { > delete mylist; > } > > Py++ is able to create the bindings and it compiles fine. However, when > accessing the 'mylist' attribute in python, I'm seeing the following > behavior: > >>>> print type(myclass.mylist) > >>>> print type(myclass.mylist) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: cannot create weak reference to 'list' object >>>> print type(myclass.mylist) > Fatal Python error: GC object already tracked > Aborted > > I think I'm going about this the wrong way, but am unsure of the proper way. > Would this be a use case for the 'inserting_code' functionality of py++? > > Thank you! > > Scott > |