From: Ammar Ali Date: 2012-05-25T19:51:41+09:00 Subject: Re: [C exte] rb_protect() with more than a single parameters --0015175ce23c269a5404c0da27ba Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, May 24, 2012 at 8:59 PM, I=C3=B1aki Baz Castillo wr= ote: > Ok, so if from C I want to call a Ruby method passing N VALUE > parameters, should I really create a Ruby Array and pass it as _data_ > in rb_protect() ?? really? is there any other way? > I did not find another way after searching for a while, including the source of all the extensions I could get my hands on. I was a little surprised too. I ended up writing my own wrappers around rb_funcall and rb_funcall2, using rb_rescue2. Here's a gist: https://gist.github.com/2787174 These come from a program that embeds ruby, not an extension, so they were written to suit those needs. For example, rescuing rb_eException might be too broad, and registering/unregistering args with the GC might not be necessary for all applications. I think this is most probably the reason why ruby does not provide such functions. In any event, I've been meaning to put these snippets out there in a related thread in hope they might help someone. I hope they help you in some way. I would be very interested in any feedback you might have. Regards, Ammar --0015175ce23c269a5404c0da27ba Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thu, May 24, 2012 at 8:59 PM, I=C3=B1aki Baz Castillo <= span dir=3D"ltr"><ibc= @aliax.net> wrote:
Ok, so if from C I want to call a Ruby method passing N VALUE
parameters, should I really create a Ruby Array and pass it as _data_
in rb_protect() ?? really? is there any other way?
I did not find another way after searching for a while, including the sour= ce of all the extensions I could get my hands on. I was a little surprised = too.

I ended up writing my own wrappers around rb_funcall and rb_funcall2, u= sing rb_rescue2. Here's a gist:

=C2=A0 https://gist.github.com/2787174

These come fr= om a program that embeds ruby, not an extension, so they were written to su= it those needs. For example, rescuing rb_eException might be too broad, and= registering/unregistering args with the GC might not be necessary for all = applications. I think this is most probably the reason why ruby does not pr= ovide such functions.

In any event, I've been meaning to put these snippets out there in = a related thread in hope they might help someone. I hope they help you in s= ome way. I would be very interested in any feedback you might have.

Regards,
Ammar

--0015175ce23c269a5404c0da27ba--