From: Michal Rokos Date: 2002-02-06T09:41:06+09:00 Subject: Re: Ruby extension for IBM Via Voice TTS Hello, Mike Hall wrote: > There's many voice and synthesis parameters that control > the speaking voice, like pitch, volume, speed, head, gender, etc. > > What's a good "Ruby way" to add these? > > - define general set_param / get_param methods > and write higher-level methods in Ruby? I use this. For example: .from_ary(array) is implemented in 'C' space, but .from_hash(hash) is in 'Ruby' space and calls .from_ary() > - define the individual methods in C? I did not understand the question. > - make them look and act like instance variables? Of course. I think that you should had in mind that you're making something for 'Ruby' people - so it should fit the Ruby's practices. So I have: xxx_set_x() and xxx_get_x() in 'C' The glue is: rb_define_class(c, "XXX", rb_cObject); rb_define_method(c, "x", xxx_get_x, ...); rb_define_method(c, "x=" xxx_set_x, ...); in 'C'. Maybe I'm wrong, but you should also use 'new' and 'initialize' methods for your objects. 'new' should allocate all memory for obj. and 'initialize' should init it. rb_define_singleton_method(c, "new", xxx_s_new, -1); rb_define_method(c, "initialize", xxx_initialize, -1); and static VALUE xxx_s_new(int argc, VALUE *argv, VALUE klass) { VALUE obj; ... /* ALLOC MEM */ obj = Data_..._Struct(...); rb_obj_call_init(obj, argc, argv); return obj; } static VALUE xxx_initialize(int argc, VALUE *argv, VALUE self) { Data_Get_Struct(self, ...); rb_scan_args(argc, argv, ...); ... /* INIT IT */ return self; } I hope it helped. Michal -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Michal Rokos Czech Technical University, Prague E-mail: m.rokos@sh.cvut.cz Jabber: majkl@jabber.cz, ICQ: 36118339 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-