Mix code of C and Ruby, need help pls. 
Author Message
 Mix code of C and Ruby, need help pls.

Hello,

I am trying to write some mix code of C and Ruby but I'm not able to
complete it and cannot find any documentation about it.

Let say I have a ruby script that looks like this:

Foo.rb
class Foo
   attr_reader :val

   def func

   end
end

I want to write the following Ruby code in C in order to access my foo
class.

obj = Foo.new
obj.func
print "Value: " + obj.val

So far, I have try those approaches in C:

rb_eval_string( "require \"Foo.rb\"" );
rb_eval_string( "obj = Foo" );
rb_eval_string( "obj.func" );

but I'm totally clueless how to do the last line. I tryed to find
something that look like this but with no success.

printf( "Value: %d", rb_eval_string( "obj.val" ) );

I also have tryed something else but I guess I'm totaly wrong since it
doesn't work at all:

VALUE obj;
rb_require( "Foo.rn" );
obj = rb_class_new( "Foo" );
rb_funcall( obj, rb_intern( "func" ), 0 );

Any help, or link to a documentation would be appreciated.

Thank you,
Ben.



Sat, 06 Aug 2005 06:41:37 GMT  
 Mix code of C and Ruby, need help pls.
Hi,

At Tue, 18 Feb 2003 07:41:37 +0900,

Quote:

> I also have tryed something else but I guess I'm totaly wrong since it
> doesn't work at all:

> VALUE obj;
> rb_require( "Foo.rn" );

                   rb

Quote:
> obj = rb_class_new( "Foo" );

rb_class_new(superclass) does create a new class inheriting
superclass.

  obj = rb_class_new_instance(0, NULL, rb_const_get(rb_cObject, rb_intern("Foo")));

Quote:
> rb_funcall( obj, rb_intern( "func" ), 0 );


--
Nobu Nakada


Sat, 06 Aug 2005 08:01:13 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Soliciting views on PLs in CS education

2. Soliciting views on PLs in CS education

3. HEX to Decimal ASCII code. pls help

4. how to code in VHDL ...??..pls help..

5. HEX to Decimal ASCII code. pls help

6. Extending ruby with mixed C/ruby classes?

7. I need some help pls

8. help needed ! pls advise on this simple question : )

9. i need help pls

10. Pls, need help...

11. Pls Help! Need binary search tree module

12. Porolog help needed, pls.

 

 
Powered by phpBB® Forum Software