From: Joel VanderWerf Date: 2001-12-09T05:48:57+09:00 Subject: [ruby-talk:27976] Re: passing a block from C to Ruby ts wrote: > > >>>>> "J" == Joel VanderWerf writes: > > J> 2. Is there a way I can call a method and indicate to Ruby that the > J> block associated with it should be the same as the block in the current > J> context? (This would be more efficient than 1.) > > See [ruby-talk:21709] > > Guy Decoux Now that I've looked at rb_obj_call_init, it looks possible to adapt it to a more general solution. Define a wrapper for rb_funcall2 that propagates the block by using the PUSH_ITER and POP_ITER macros: void rb_funcall2_with_block(obj, meth, argc, argv) VALUE obj; ID meth; int argc; VALUE *argv; { PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT); rb_funcall2(obj, meth, argc, argv); POP_ITER(); } I haven't tried this--even if it worked in a simple example, I don't have enough experience with the Ruby source to know whether this makes sense in general. -- Joel VanderWerf California PATH, UC Berkeley mailto:vjoel@path.berkeley.edu Ph. (510) 231-9446 http://www.path.berkeley.edu FAX (510) 231-9512