Passing C Struct to Ruby

M

Mido Peace

hey !!

I'm newbie in Ruby ,
Actually , I wanna call some C methods and Structure from Ruby , But
Still dont knw how to do


in C ...

int VALUE my_str_new(VALUE arg)
{
my_struct *str =init_Struct(arg) ;
return *str ;
}
...?!

I dont know how to tell Ruby about my C struct and its methods( or
create equivalent struct (keeping the C methods ) in Ruby)

Thx
 
I

Iñaki Baz Castillo

El Martes, 19 de Enero de 2010, Mido Peace escribi=C3=B3:
in C ...
=20
int VALUE my_str_new(VALUE arg)
{
my_struct *str =3Dinit_Struct(arg) ;
return *str ;
}

This is wrong. Any Ruby C function must return a VALUE object. This is, a R=
uby=20
method cannot return a C integer or a C struct.

So you need to translate the above C struct into a Ruby hash, Ruby struct o=
r a=20
custom Ruby class instance.

But definitively I recommend you to look for Ruby C extensions tutorials.


=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,282
Latest member
RoseannaBa

Latest Threads

Top