# Help with turning procs into C function pointers

**URL:** <https://www.ruby-forum.com/t/help-with-turning-procs-into-c-function-pointers/150966>\
**Category:** Ruby-Gnome 2\
**Created:** [October 15, 2008, 11:22am UTC](https://www.ruby-forum.com/t/help-with-turning-procs-into-c-function-pointers/150966 "2008-10-15T11:22:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_SSTownley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Andrew\_SSTownley](https://www.ruby-forum.com/u/Andrew_SSTownley)\
**Post date:** [October 15, 2008, 11:22am UTC](https://www.ruby-forum.com/t/help-with-turning-procs-into-c-function-pointers/150966/1 "2008-10-15T11:22:26Z")

</div>

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)  
end  
end

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,

## ast

Andrew S. Townley [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://atownley.org](http://atownley.org)

---

<div class="post-metadata">

**Author:** ![Andrew\_SSTownley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Andrew\_SSTownley](https://www.ruby-forum.com/u/Andrew_SSTownley)\
**Post date:** [October 18, 2008, 7:39am UTC](https://www.ruby-forum.com/t/help-with-turning-procs-into-c-function-pointers/150966/2 "2008-10-18T07:39:08Z")

</div>

Hi,

In [1224062496.7270.77.camel@linna](mailto: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](mailto: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.

## Thanks,

kou
