Passing C Struct to Ruby

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 dont know how to tell Ruby about my C struct and its methods( or
create equivalent struct (keeping the C methods ) in Ruby)

checkout ffi, ruby ffi swig generator, and

either that or if you want to write a c extension google for “ruby c
extension”

-r

El Martes, 19 de Enero de 2010, Mido P. escribió:

in C …

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

This is wrong. Any Ruby C function must return a VALUE object. This is,
a Ruby
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 or a
custom Ruby class instance.

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