你还得写属性 wrapper method
static VALUE get_connected(VALUE self) {
struct rb_connect_information* info;
Data_Get_Struct(self, struct rb_connect_information, info);
return INT2NUM(info->connected);
}
static VALUE get_servername(VALUE self) {
struct rb_connect_information* info;
Data_Get_Struct(self, struct rb_connect_information, info);
return info->servername;
}
然后声明方法才能在 ruby 中调用
rb_define_method(rb_cConnectInfo, "connected", get_connected, 0);
rb_define_method(rb_cConnectInfo, "servername", get_servername, 0);
文档看一遍 http://www.rubydoc.info/stdlib/core/file/README.EXT
另外一个包装的方法是用 FFI, 不用写那么多 wrapper...