From: Jeff Ward Date: 2002-05-14T11:44:09+09:00 Subject: Re: rb_define_variable for instance variables? --------------060802020804050204020406 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit That was actually the first thing I tried, and it's find if I'm trying to access the variables outside of the class, but not inside. E.g. if I had a ruby created method called update which changed an instance variable with those parameters, it wouldn't call them. E.g. the method is like this: def Update @pos = 24 end pos would not get updated on the C side of things, even if those methods were defined. This is kinda confusing but it's the way I would like to do it. The best explanation I can come up with is that in my program, C is really providing the interface, where as Ruby is providing the implementation, so I need functions to change instance variables and have C reflect the change. Hope that clears things up. -Jeff Sean Chittenden wrote: >>Is there a way to have a shared instance variable like those defined >>by rb_define_variable? Where would I find the documentation on >>that? >> > >An instance variable in C is two methods. In your Init() method, >you'd define two methods, a get and set method. From mod_ruby: > > rb_define_method(rb_cApacheRequest, "cache_resp", > request_get_cache_resp, 0); > rb_define_method(rb_cApacheRequest, "cache_resp=", > request_set_cache_resp, 1); > >That help? -sc > --------------060802020804050204020406 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit That was actually the first thing I tried, and it's find if I'm trying to access the variables outside of the class, but not inside.  E.g. if I had a ruby created method called update which changed an instance variable with those parameters, it wouldn't call them.  E.g. the method is like this:

def Update
        @pos = 24
end

pos would not get updated on the C side of things, even if those methods were defined.  This is kinda confusing but it's the way I would like to do it.  

The best explanation I can come up with is that in my program, C is really providing the interface, where as Ruby is providing the implementation, so I need functions to change instance variables and have C reflect the change.  Hope that clears things up.

-Jeff

Sean Chittenden wrote:
Is there a way to have a shared instance variable like those defined
by rb_define_variable? Where would I find the documentation on
that?

An instance variable in C is two methods. In your Init() method,
you'd define two methods, a get and set method. From mod_ruby:

rb_define_method(rb_cApacheRequest, "cache_resp",
request_get_cache_resp, 0);
rb_define_method(rb_cApacheRequest, "cache_resp=",
request_set_cache_resp, 1);

That help? -sc


--------------060802020804050204020406--