Hi
I'm trying to wrap up a library, and one of its functions accepts a
callback function as an argument. What I want to do is to make the
function exported to ruby accept a block, and yield this block on the
callback function. So, to do that, I guess what I need is some way to do
the equivalent of
def foo(&block)
...
end
in C, ie, store the code block in a variable so I can pass it around.
I could make my code work using a Proc object explicitely as one of the
C function's arguments, as in
static VALUE
my_func(..., VALUE block)
{
...
func_with_callback(..., my_callback, (void *)block);
...
}
static void
my_callback(void *arg)
{
rb_funcall((VALUE)arg, rb_intern("call"), 0);
}
And from ruby I use it as
obj.my_func(proc { puts 'blah' })
How could I be able to call it as
obj.my_func { puts 'blah' }
and still be able to pass the code block to the callback function?
Thanks in advance,
Andre