From: emilie3012@... (Steve Hart) Date: 2003-04-10T11:42:27+09:00 Subject: Re: tutorial on embedding ruby (review) ptkwt@shell1.aracnet.com (Phil Tomson) wrote in message news:... > In article <200304092336.07600.armin@xss.de>, > Armin Roehrl wrote: > >> http://metaeditor.sourceforge.net/embed/ > >Figure 3 alone is one reason to look at it. > >http://metaeditor.sourceforge.net/embed/cleanup.png > > > > Figure 4 is pretty cool too. > > I'm going to have to take a look at this part: > "Most people think that SWIG can be used ONLY for ruby extensions. But if > you are clever you can actual use it for embedding. " > > Phil Hi Simon, I'm in the middle of embedding ruby into a c++ project and read the tutorial with interest. It's great to see something out there that addresses this issue. I've already emailed you with some specific questions but forgot to add commenst for the tutorial.I'm a newcomer to ruby and swig so any info is great to see So some points that I would find usefull would be: 1) A more detailed explanation of THE GC interaction would be good. I' not sure if you need to do both marking and rb_global_variable and/or rb_gc_register_address. If I call rb_ary_new2 in my C code should I always inform the GC? I understand that I need to use a mark function for wrapped c classes but where do I get the VALUE from to pass to the mark function? If I am marking and object correctly what do I do when I want to free it off - just stop marking? The example given under 'speed issues' protects the object list (using rb_gc_register_address) but what do I do if I want to free of just some of the objects in the list?. Also, what happend if the GC runs between objects = rb_ary_new() and rb_gc_register_address(&objects); ? Or can this never happen. 2) An example explaining finializers would be nice - still not sure if I need them. Since I'm probably what Matz would describe as a 'normal' user perhaps I should stear clear!. 3) rb_require over rb_load_protect - I started off using rb_require but then found that if rb_require fails with a script error and I then corrected the script re re-rb_requiring ignored the changes - I assume the script is cached. Switching to rb_load_protect reloads the script each time - but is this correct? What does the second argument to rb_load_protect do 3) More detail for the swig version - especially for the case when a ruby class inherits a swigged up c class and you need to pass a swigged up c class instance throug to it and then back out again e.g. c++: SwigClass1 *sg = new SwigClass1(); sgValue = Data_Wrap_Struct(rb_path2class("MyModule::SwigClass1"),0,0,(void *)sg); oClass = rb_const_get(rb_cObject, rb_intern("SwigClass2")); oObj = rb_funcall(oClass, rb_intern("new"), 1,sgValue); ruby: class MyClass < MyModule::SwigClass2 def initialize(swigClassValue) super(swigClassValue) end end 4) Also under speed issues - should'nt void mystruct_alloc(VALUE klass) return VALUE? All this is, of course, relevant to me at the moment and I don't expect answers (well, some would be nice) but I hope it helps. I'm new to newsgroups too so I don't even know what all the arreviations and smiley colons mean yet! Cheers Steve