Re: C and Ruby...

From: nobu.nokada@...
Date: 2002-08-11 22:19:48 UTC
List: ruby-core #319
Hi,

At Mon, 12 Aug 2002 02:09:55 +0900,
Kostas Katsamakas wrote:
>     How can i add an instance variable in a ruby class object?

  rb_ivar_set(obj, rb_intern("@foo"), Qtrue);
or
  rb_iv_set(obj, "@foo", Qtrue);

> For example i would like to add an instance variable that would hold a
> pointer to
> a C structure and would also like to be able to retrieve its value in C.

Ruby object's instance variable MUST be a ruby's VALUE, not a
pointer.

>     I have also created a class instance by calling:
> VALUE obj = rb_string_eval("A.new");
> How can i call its methods from C?

  rb_funcall(obj, rb_intern("method"), n, arg1, arg2, ...)

> If anyone could help me somehow i would be gratefull.
> I have searched but couldn't find documentation on these matters.

See README.EXT.

-- 
Nobu Nakada

In This Thread

Prev Next