#include "rucy.h" using namespace Rucy; struct Struct { int num; Struct () : num(0) {} };// Struct static Class cStruct; RUCY_VALUE_FROM_TO(Struct, cStruct) /* alloc function. */ static VALUE alloc(VALUE klass) { return new_type(klass); } /* get num. */ static VALUE get_num(VALUE self) { Struct* obj = to(self); if (obj) return value(obj->num); } /* set num. */ static VALUE set_num(VALUE self, VALUE num) { Struct* obj = to(self); if (obj) obj->num = to(num); } void Init_struct () { Module mRucy = rb_define_module("Rucy"); Module mTester = rb_define_module_under(mRucy, "Tester"); cStruct = rb_define_class_under(mTester, "Struct", rb_cObject); rb_define_alloc_func(cStruct, alloc); rb_define_method(cStruct, "num", RUBY_METHOD_FUNC(get_num), 0); rb_define_method(cStruct, "num=", RUBY_METHOD_FUNC(set_num), 1); }