Forum: Ruby-Gnome 2 Help with turning procs into C function pointers

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Andrew S. Townley (Guest)
on 2008-10-15 13:22
(Received via mailing list)
Hi Guys,

I've been looking at the way the signal dispatcher works in
rbgobj_signal.c to try to figure out how to call an exteral C function
which takes a callback function pointer.  I have to say that being
unfamiliar with extending Ruby in C (except from getting luck with some
fairly blind cloning of existing bindings), being unfamiliar with the
API used within the ruby-gnome2 bindings and really not being all that
familiar with using GTK+ from C, I'm having some trouble figuring out
exactly what I need to do.

Given the following

typedf void (*callback)(char *p1, int *p2);
void my_function(int x, callback fn);

How would I implement the wrapper C function for the ruby class, e.g.

class Foo
  def my_function(x, &block)

but in C?

I know this isn't specifically about ruby-gnome2, but I'm experimenting
with a set of bindings for GtkHTML3 since I'm not having much luck with
GtkHTML2.  Since I'm trying to make it consistent with what's already
part of the official bindings in case anyone else wants it, I figured
this was the best place to ask.

Thanks in advance,

Andrew S. Townley <removed_email_address@domain.invalid>
Kouhei S. (Guest)
on 2008-10-18 09:39
(Received via mailing list)

In <1224062496.7270.77.camel@linna>
  "[ruby-gnome2-devel-en] Help with turning procs into C function
pointers" on Wed, 15 Oct 2008 09:21:36 +0000,
  "Andrew S. Townley" <removed_email_address@domain.invalid> wrote:

> end
> but in C?

callback needs to accept extra void * user_data
argument. The argument should be used to pass Ruby object.

This topic is locked and can not be replied to.