How do i stop a block being passed on?

J

John Mair

Hello friends,

Im writing a ruby C API program, and i have this difficulty:

VALUE
m_func1(VALUE self) {
m_func2();
}



the problem i have is that if a block is passed to m_func1 it seems to
also
be passed onto m_func2, how do i stop it being passed on? is there a way
to
'delete' a block after i've finished with it? (i.e yielded to it)

thx

john
 
T

Tim Pease

Hello friends,

Im writing a ruby C API program, and i have this difficulty:

VALUE
m_func1(VALUE self) {
m_func2();
}



the problem i have is that if a block is passed to m_func1 it seems to
also
be passed onto m_func2, how do i stop it being passed on? is there a
way
to
'delete' a block after i've finished with it? (i.e yielded to it)

You need to create is a new ruby_frame for m_func2 to operate in. The
frame contains all the information about what blocks are available,
the scope, local variables, self, etc.

The only way to get a new ruby_frame is to use rb_funcall instead of
directly calling m_func2.


VALUE
m_func1(VALUE self) {
rb_funcall(self, rb_intern("func2"), 0);
}


This code is going to be quite slower than just calling m_func2
directly. If performance is what you are after, I would recommend
breaking out the core functionality of m_func2 into an internal
function (one that is not exposed to the ruby interpreter). m_func1
would call this internal function, and you would create a new m_func2
that handles a block and calls this same internal fucntion.

Blessings,
TwP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top