Re: [pygccxml-development] Exposing boost::python::list
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2011-08-04 15:23:34
|
Thank you for problem & solution contribution :-) On Tue, Aug 2, 2011 at 11:31 PM, Scott Sturdivant <sc...@bi...> wrote: > 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 >> > > ------------------------------------------------------------------------------ > BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA > The must-attend event for mobile developers. Connect with experts. > Get tools for creating Super Apps. See the latest technologies. > Sessions, hands-on labs, demos & much more. Register early & save! > http://p.sf.net/sfu/rim-blackberry-1 > _______________________________________________ > pygccxml-development mailing list > pyg...@li... > https://lists.sourceforge.net/lists/listinfo/pygccxml-development > |