Lenny
(Lenny)
1
Hi,
i have a Ruby class which uses a wrapped C struct for housekeeping it’s
members:
struct
{
VALUE bar;
} foo;
and use the following function for the class methode “bar()”:
static VALUE
getBar( VALUE self )
{
foo* p;
Data_Get_Struct( self, foo, p );
return p->bar;
}
Now i don’t know how to write a corresponding “bar=()” function. Can anybody
give me a hint? iv_set_var() seems to be unnecessary inefficient.
Thanks
Lenny
ts1
(ts)
2
Now i don't know how to write a corresponding "bar=()" function. Can anybody
give me a hint? iv_set_var() seems to be unnecessary inefficient.
static VALUE
setBar(VALUE self, VALUE obj)
{
foo *p;
Data_Get_Struct(self, foo, p);
p->bar = obj;
return obj;
}
/* ... */
rb_define_method(Foo, "bar", getBar, 0);
rb_define_method(Foo, "bar=", setBar, 1);
p.s. : don't forget to have a mark function for your struct and mark p->bar
Guy Decoux
Lenny
(Lenny)
4
Oops, sorry. This canceled reply made it through. blush
Thanks for the reply the mark-hint was very valuable for me.
Bye
Lenny
···
On Saturday 29 March 2003 21:39, Lenny wrote:
Hi,
Data_Get_Struct(self, foo, p);
p->bar = obj;
[…]
p.s. : don’t forget to have a mark function for your struct and mark
p->bar