Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-04-08 03:47:33


It's not the widget type that needs to be added to Boost, but the callback
function pointer type Fl_Callback. Boost has no way of knowing what type
such a function pointer should be converted into...

Well, technically, maybe it could know. Getting it to work would be quite a
trick. If you'd like to add a feature request to the tracker at, it
would be much appreciated.

In the meantime, you would have to create your own from_python/to_python

One approach you might consider is to have the to_python function call
boost::python::detail::new_wrapped_function_pointer(f) from
boost/python/detail/functions.hpp. Then you'll need a from_python function
which can check that its PyObject* argument has the type
boost::python::detail::function::type. This approach allows the wrapped
function pointer to be called from Python just like any other function.

Another, probably simpler way to deal with the problem would be to create a
trivial C++ class which wraps a Fl_Callback:

  struct Fl_Callback_wrapper {
    Fl_Callback callback;

if you first instantiate its class_builder:

  template class boost::python::class_builder<Fl_Callback_wrapper>;

you should then be able to declare the following from_python/to_python


  Fl_Callback from_python(PyObject* o, boost::python::type<Fl_Callback>)
    return from_python(PyObject* o,

  Fl_Callback from_python(PyObject* o,
    boost::python::type<Fl_Callback const&>)
    return from_python(PyObject* o,

  PyObject* to_python(Fl_Callback cb)
    Fl_Callback_wrapper w;
    w.callback = cb;
    return to_python(cb);



----- Original Message -----
From: "Kevin Dahlhausen" <kdahlhaus_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, April 08, 2001 2:00 AM
Subject: [boost] BPL - function pointers / callbacks?

> Hello,
> I'm looking into wrapping the Fast Light Toolkit with
> BPL. Some member functions take pointers to static
> functions which will be used as callbacks.
> The callback function signature is:
> void callback( Fl_Widget *, void *)
> This is registered with:
> typedef void (Fl_Callback)(Fl_Widget *, void *);
> void Fl_Widget::callback(Fl_Callback *c, void *p);
> The error this results in is:
> /home/kpd/src/boost-1.20.2/boost/python/caller.hpp:653:
> no matching function for call to `from_python
> (PyObject *&, boost::python::type<void (*)(Fl_Widget
> *, void *)>)'
> /home/kpd/src/boost-1.20.2/boost/python/conversions.hpp:80:
> candidates are: long int from_python(PyObject *,
> boost::python::type<long int>)
> .
> .
> .
> So, do I need to add the widget type to boost, that
> doesn't sound right.
> Do I need to change the interface to a Py_Object?
> Searching the archives did not reveal anything.
> Would someone be kind enough to post an example of
> registering a callback function?
> Thanks for your help!
> =====
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Kevin Dahlhausen kdahlhaus_at_[hidden]
> "Do or do not. There is no 'Try.' Yoda
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>
> Your use of Yahoo! Groups is subject to

Boost list run by bdawes at, gregod at, cpdaniel at, john at