From: Andre Nathan Date: 2009-03-30T01:52:49+09:00 Subject: Re: Passing block in C Hi Peter, On Sun, 2009-03-29 at 23:30 +0900, Peter Zotov wrote: > Hi. > > How can I call Ruby function from C with block? You can use rb_iterate(): static VALUE foo_i(VALUE x, VALUE dummy) { rb_p(x); return Qnil; } static VALUE rb_foo(VALUE self) { rb_yield(INT2FIX(42)); return Qnil; } static VALUE call_foo(VALUE klass) { return rb_funcall(klass, rb_intern("foo"), 0); } void Init_myclass(void) { VALUE klass = rb_define_class("MyClass", rb_cObject); rb_define_singleton_method(klass, "foo", rb_foo, 0); rb_iterate(call_foo, klass, foo_i, (VALUE)NULL); } Best, Andre