chromatic wrote:
On Friday 18 January 2008 20:25:16 Allison Randal wrote:
It's true that the generalized solution for varying callback signatures
doesn't exist yet, but it's easy enough to create your own C callback
layer, with a separate C function for each callback you need. (Note, not
one-per-signature, but one-per-callback.) The callback functions can
invoke a Parrot sub that they lookup by name, register a callback sub
with the concurrency scheduler, or simply directly perform the actions
needed.
I'm not even sure *that* will work. To invoke a Sub PMC from C, you need to
pass in an Interp as well as the PMC. Unless you know both of those at
compile time, I'm not sure how to make the callback mechanism work.
The concurrency scheduler stores the interp, so it's not a problem for
invoking the PIR callback Sub. But, the current way of looking up the
concurrency scheduler is through the interpreter, so that just pushes
the problem back a step.
Really, any scheduler will do, since it can pass a message to all the
other schedulers. So, the C callback function can just grab the 0th
interpreter from the global interp array and send a callback event to
that scheduler. The actual PIR Sub for the callback can be registered as
a handler in the scheduler, and invoked by the scheduler as a handler
for the callback event.
Allison