[C++-sig] Re: Using a phython function as callback

David Abrahams dave at boost-consulting.com
Tue Jun 24 23:28:08 CEST 2003


"jochen" <jochen at neverEngine.com> writes:

> Thanks for the hint, but I can't figure out how to use it correctly:
>
> What I do is:
>
> SelectableObject*			pSelectable;
> ...
> PyObject*				pCB		= pSelectable->GetOnUpdateSelectionCallBack();
>
> if ( PyCallable_Check( pCB ) )
> {
> 	boost::python::call< void >( pCB, pSelectable );
> }
>
> Py_DECREF( pCB );
>
>
> But the call raises a exection:
> boost::python::error_already_set

That means the call produced a python exception.  If you're embedding
Python, see the main() function in libs/python/test/embedding.cpp for
a way to see what that was.  If you're writing extension modules,
just let it propagate back to Python and examine the backtrace.

> How do I correctly convert the instance of type SelectableObject to
> a valid PyObject ?


  python::object x(*pSelectable);


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list