Vincent Fourmond wrote:
> Hello !
> 
>> Then later on I wan't to use it like this:
>> 
>> void call(void)
>> {
>>   rb_funcall(ref, rb_intern("some_method"), 0, 0);
>> }
> 
>   How comes this function has no parameters ? Is it being called from
> ruby, or only from C code ?
>

Thank you for the reply, I'll try to clear things up a bit and explain 
what I want to do.

The function is just an example for the sake of making my question a bit 
clearer. The real functions I am using has parameters. Those functions 
such as the one above will only be called from C code.

> 
>   I tend to think that using global variables is not a really good idea.
>  We need a bit more context about what you want to do. Is it a class ?
> Will it have several instances ?
> 
>   In the latter case, have a look at rb_iv_get and rb_iv_set to get/set
> instance variables of a class instance, something like
> 
>   rb_iv_set(self, rb_intern("@variable"), arg); /* in init(...) */
> 
>   and
> 
> 
> rb_funcall(rb_iv_get(self,rb_intern("@variable")),rb_intern("some_method"),
> 0, 0); /* in call */
> 

Yes, I'm writing a tiny Ruby class in C that wraps and uses a bison/flex 
generated parser. The saved variable reference will be used for making 
calls on the ruby instance. When those calls are made self is long gone 
out of scope sice it's the parser who triggers the method call. The C 
Ruby class just acts as a proxy or adapter between the parser and the 
Ruby object.

>   Don't forget as well that every single C function that can be called
> directly from ruby should probably have at least one VALUE parameter and
> *must* return a VALUE.
> 
>   Cheers !
> 
> 	Vince

As mentioned above, it's not invoked from Ruby.


Thanx again, Christer.

-- 
Posted via http://www.ruby-forum.com/.