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
On Aug 12, 2008, at 12:16 AM, John M. wrote:
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