Leopold Toetsch wrote:


On Oct 25, 2005, at 23:32, Nick Glencross wrote:

I was looking at callbacks the other evening. Am I right in thinking that only two callback prototypes are supported, or have I missed a trick there as well?


That's right. There are 2 callbacks (functions with 2 arguments only), one with the *transparent* (void *) user argument first, and one with it as second arg.

Before including one or more 3 arg variants, I'd prefer to have some investigations (and results ;-) WRT possible alternatives like libffi.

As a bit of background to my original posting, I was trying to write a nice NCI example using Glut/GL. Many of the Glut callbacks have no arguments what-so-ever, so this is currently out of the question.

While libffi provides a flexible calling framework, I'm still trying to find if it provides a scheme for callbacks or introspection of arguments passed to a function. It's difficult to find the latest version as it is now part of gcc.

Although I haven't fully evaluated it yet, I like the look of ffcall: http://www.haible.de/bruno/packages-ffcall.html

It seems to provide all the functionality that we would want. I still can't see how it works under the hood, but it allows you to create a magic function pointer which has values bound to it.

We would then be able to create an ffcall callback with a single unified C trampoline, and bind the parrot target, its signature and any userdata. This could then be registered as the library callback.

When the C trampoline is called, it need do little more than extract values and call Parrot_runops_fromc_args.

The point is (unless I've misunderstood the documentation), that we could even support libraries that have awkward callbacks (such as ones that don't have any user attributes) and multi argument prototypes.

Its licensing might be a problem -- GPL. Everything else looks perfect.

I'll see if I can come up with a proof of concept over the next few days.

Nick

Reply via email to