I am writing a C extension and wish to call a block from within one of
my extension’s methods.
Ruby calling code
cExtensionInstance.readtoken( 0, 10 ) { puts "hello world" }
In the C function providing the readtoken method, I can have code
like:
VALUE blockProc;
if ( rb_block_given_p() )
{
blockProc = rb_f_lambda();
// how do I now call the block pointed to by blockProc?
}
My question is, what Ruby function do I use from within my C method
function to call blockProc?
Should I be calling rb_yield() or is there a simpler function to call?
Many thanks,
Phil
Just call rb_yield. You don’t need to call rb_f_lambda.
(snip)
···
On Tue, 01 Oct 2002 16:46:27 +0000, Philip Bacon wrote:
My question is, what Ruby function do I use from within my C method
function to call blockProc?
Should I be calling rb_yield() or is there a simpler function to call?
Hi Phil,
I just want to say, that writing a C extension in Ruby is simply another
world beyond Ruby and C. Even if someone is a really great Ruby
programmer and a really great C programmer, he still needs to learn how to
write a C extension in Ruby. (Especially, writing C in the presence of a
garbage collector can be tricky if the data structure is overly complex.)
Currently not much documentation exists, and if you just scanned the
previous discussions in this newsgroup you may find several things that
are useful.
Finally, if you write C by just translating the Ruby code to a C code, you
may want to look at rb2c
(http://easter.kuee.kyoto-u.ac.jp/~hiwada/ruby/rb2c/),
which hopefully can do the job automatically for you (I haven’t tried it
myself). Then only if you want to highly optimize your code, you can
start writing the C extension by hand.
Regards,
Bill
···
==========================================================================
Philip Bacon philip.bacon@nextpage.com wrote:
I am writing a C extension and wish to call a block from within one of
my extension’s methods.
Hi Phil,
I just want to say, that writing a C extension in Ruby is simply another
world beyond Ruby and C. Even if someone is a really great Ruby
programmer and a really great C programmer, he still needs to learn how to
write a C extension in Ruby. (Especially, writing C in the presence of a
garbage collector can be tricky if the data structure is overly complex.)
Currently not much documentation exists, and if you just scanned the
previous discussions in this newsgroup you may find several things that
are useful.
The file README.EXT (distributed with Ruby) and the Extending Ruby
section of the Pickaxe book are both excellent sources of information.
I believe the Ruby Developer’s Guide includes a brief section on writing
bindings as well.
···
- William Djaja Tjokroaminata (billtj@y.glue.umd.edu) wrote:
Finally, if you write C by just translating the Ruby code to a C code, you
may want to look at rb2c
(http://easter.kuee.kyoto-u.ac.jp/~hiwada/ruby/rb2c/),
which hopefully can do the job automatically for you (I haven’t tried it
myself). Then only if you want to highly optimize your code, you can
start writing the C extension by hand.
Regards,
Bill
Philip Bacon philip.bacon@nextpage.com wrote:
I am writing a C extension and wish to call a block from within one of
my extension’s methods.
–
Paul Duncan pabs@pablotron.org pabs in #gah (OPN IRC)
http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562