[C++-sig] set python attribute from C++
Gennadiy Rozental
rogeeff at gmail.com
Thu Jul 17 09:11:18 CEST 2008
Gennadiy Rozental <rogeeff <at> gmail.com> writes:
Forgot to mention two critical bits of info
> class PythonBase : public Base {
> public:
// release python object
~PythonBase() { bp::decref( m_object ) }
...
> Base*
> PythonFactory::create(...)
> {
> bp::object obj = m_py_type();
> PythonBase* ptr = bp::extract<PythonBase*>( obj );
>
> ptr->init( obj );
// make sure python object is not destroyed once we leave this scope
bp::incref( obj );
> return ptr;
> }
Gennadiy
More information about the Cplusplus-sig
mailing list