[Gambas-user] Callbacks in Gambas (was Re: Signal management)

Benoît Minisini gambas at ...1...
Wed Jul 14 14:12:38 CEST 2010


> > > Nice thing. But now I have a further question: is it possible to
> > > implement generic callbacks in Gambas?
> > > I mean - many libraries have functions where you specify a callback to
> > > be called, like the glib function g_signal_connect(); it would be nice
> > > to implement them, even partly, without resorting to write a gambas
> > > component. May be that by using libffi it is possible to implement them
> > > fully, but even a simple event could do. My problem now is that using
> > > ALSA, I must poll continuously to see if some event is coming in,
> > > wasting a lot of CPU and losing precision. With a callback if would be
> > > much simpler...
> > > 
> > > I hope I have been clear enough.
> > > 
> > > Regards,
> > > Doriano
> > 
> > It is possible, I will trying to do that. There is a lot of magic
> > involved behind that, hopefully handled by the libffi library.
> > 
> > Alas, that library is not very well documented, so it will take a little
> > time, and I'm not 100% sure it will work as expected.
> > 
> > Regards,
> 
> You should be happy with revision #3040.
> 
> Regards,

Some little information about callbacks:

If you want to use a Gambas function as a callback for an extern function, you 
just have to:

1) Declare the extern function argument that will receive the function address 
as "Pointer".

2) Use the Gambas function name when calling the extern function.

Note that you can use any private or public Gambas function. You can even use 
non-static methods: but beware that the object the method applies on is 
captured by the callback, and released at the end of the program only.

Waiting for your returns!

Regards,

-- 
Benoît Minisini




More information about the User mailing list