[gambit-list] FFI and Callbacks

Diogo F. S. Ramos diogofsr at gmail.com
Wed Apr 6 14:20:46 EDT 2011


The last thread [0] got me thinking about a problem that I'm having with
registering callbacks.

I'm still in the quest of making a GTK+ application and I'm jumping
between designs.

GTK+ have the following strategy:

If one wants to call a function when, say, a button is clicked, one
needs to register this function, which have a specific signature, with
the following function:

g_signal_connect(button, "clicked", func, data);

func is the callback to be called and data is a void* that will be
passed to func.

My problem is: how do I allow registering scheme callbacks?

I don't have a clear idea on how to convert a lambda to a C function or
even how to pass it.

Also, when running my .o1 with the interpreter, I don't have a
representation of a C function and I can't use (c-define) to make one.

My present idea is the following:

At the moment I instantiate a GtkButton (button) I also register a proxy
"clicked" callback. This proxy procedure will read a list and execute
the procedures listed there. So, when I want to register a new callback
I don't actually register it at the C level, but I append it to the
proxy's list so, when I click the button, the proxy is called and all
the procedures listed all called.

What do you think?

Is there a way to do it without the proxy?

[0] http://article.gmane.org/gmane.lisp.scheme.gambit/4948

-- 
Diogo F. S. Ramos



More information about the Gambit-list mailing list