Extending Ruby, calling a function from C

Posted by ThePower on Stack Overflow See other posts from Stack Overflow or by ThePower
Published on 2010-05-10T08:41:55Z Indexed on 2010/05/10 8:44 UTC
Read the original article Hit count: 411

Filed under:
|
|
|

Hi, I'm writing an app that calls ruby code from c. I am having a little difficulty and wondered if anyone could point me in the rite direction.

I currently have in my C.

#include ruby.h

main()
{
  ruby_init();
  rb_require("myRubyFile");
  rb_funcall(rb_module_new(), rb_intern("RubyFunction"), 0, NULL);
}

My ruby file is in the same directory as my c file and is called myRubyFile.rb and contains a definition of the function RubyFunction().

This is a cut down of what I actually want to do, just making it more readable for others. I just require some feedback as to whether this is the correct method to call ruby code from my c file.

Regards

© Stack Overflow or respective owner

Related posts about ruby

Related posts about c