[C++-sig] Passing opaque data to C++ callback from Python

Peter LaDow pladow at gmail.com
Fri Dec 19 05:26:46 CET 2014


On Thu, Dec 18, 2014 at 8:10 PM, Stefan Seefeld <stefan at seefeld.name> wrote:
> That sounds a bit confusing to me. :-)
> Typically, if you associate state with a callback (a "closure"), you
> think of it as an object whose member function is the callback. But
> here, the callback function lives in Python, while you want to associate
> state from the C++ runtime...

Exactly!  There may be a better way to do what I'm trying to do.  The
relationship is one-to-many (i.e. a single Python object can be
associated with many C++ objects).  Because of this relationship, I
need some context in which the Python object is called in order to
make sure each of the C++ objects is aware that the callback occurred.
That is, I don't want numerous C++ objects triggering a callback into
Python.  That shared information (whether or not the Python callback
occurred) must be stored somewhere.  Since I have no control over the
order those C++ objects are invoked (they are passed to a 3rd party
library), so when the first one is invoked, it needs to notify the
others not to do the Python callback.

Anyway, as you noted, I figured something out.  I'm sure there's a
more clever way to do this.  But I'm an EE converted to the software
world and I'm probably not thinking like a software engineer.

Thanks,
Pete


More information about the Cplusplus-sig mailing list