本人自行删除

lanjingyu · 2015年11月23日 · 最后由 luikore 回复于 2015年11月24日 · 7253 次阅读

本人自行删除

你还得写属性 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...

2 楼 已删除
需要 登录 后方可回复, 如果你还没有账号请 注册新账号