[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Invoking method with a block in C extension

Dmitry V. Sabanin

11/22/2003 1:34:00 PM

Hi.
I'm converting some of my ruby code to C extension for better perfomance.
I ran into problems with executing methods that take blocks.
I.e. in ruby i have
string.gsub!(/regexp/) { |subst| ... }
and i can't find the way to translate it to C. I tried to search through
ruby-talk archives, but I couldn't find anything usefull.
As far as I was looking at problem, I found rb_iterate, rb_yield, but I
couldn't clearly understand what's their purpose, and how to get them all
together to achieve what I want.
Could somebody please explain me how can I implement this ruby code in C?
I'd really appreciate any help. Thanks in advance!
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.


3 Answers

ts

11/22/2003 2:20:00 PM

0

>>>>> "D" == Dmitry V Sabanin <sdmitry@lrn.ru> writes:

D> As far as I was looking at problem, I found rb_iterate, rb_yield, but I
D> couldn't clearly understand what's their purpose, and how to get them all
D> together to achieve what I want.

Look in enum.c in the distribution of ruby, you have examples for call to
rb_iterate



Guy Decoux


Mauricio Fernández

11/22/2003 2:55:00 PM

0

On Sat, Nov 22, 2003 at 10:34:27PM +0900, Dmitry V. Sabanin wrote:
> Hi.
> I'm converting some of my ruby code to C extension for better perfomance.
> I ran into problems with executing methods that take blocks.
> I.e. in ruby i have
> string.gsub!(/regexp/) { |subst| ... }
> and i can't find the way to translate it to C. I tried to search through
> ruby-talk archives, but I couldn't find anything usefull.
> As far as I was looking at problem, I found rb_iterate, rb_yield, but I
> couldn't clearly understand what's their purpose, and how to get them all
> together to achieve what I want.
> Could somebody please explain me how can I implement this ruby code in C?
> I'd really appreciate any help. Thanks in advance!

I was surprised to see that rb_funcall propagates the block passed with
rb_iterate, so there's 2 solutions (attached).

--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Linux! Guerrilla UNIX Development Venimus, Vidimus, Dolavimus.
-- Mark A. Horton KA4YBR, mah@ka4ybr.com

Dmitry V. Sabanin

11/23/2003 4:41:00 AM

0

On Saturday 22 November 2003 21:55, Mauricio Fernández wrote:
> On Sat, Nov 22, 2003 at 10:34:27PM +0900, Dmitry V. Sabanin wrote:
> > Hi.
> > I'm converting some of my ruby code to C extension for better perfomance.
> > I ran into problems with executing methods that take blocks.
> > I.e. in ruby i have
> > string.gsub!(/regexp/) { |subst| ... }
> > and i can't find the way to translate it to C. I tried to search through
> > ruby-talk archives, but I couldn't find anything usefull.
> > As far as I was looking at problem, I found rb_iterate, rb_yield, but I
> > couldn't clearly understand what's their purpose, and how to get them all
> > together to achieve what I want.
> > Could somebody please explain me how can I implement this ruby code in C?
> > I'd really appreciate any help. Thanks in advance!
>
> I was surprised to see that rb_funcall propagates the block passed with
> rb_iterate, so there's 2 solutions (attached).
Thank you very much, that code saved me :)

--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.