------ art_10057_29124415.1198605304976 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I'm doing this because I SWIG doesn't work for my current wrapping project. Also, SWIG generates static method wrappers. I'm trying to do this dynamically (see Boost.Python: http://www.boost.org/libs/python/doc/) Jason On Dec 25, 2007 4:27 AM, Axel Etzold <AEtzold / gmx.de> wrote: > > -------- Original-Nachricht -------- > > Datum: Tue, 25 Dec 2007 04:02:38 +0900 > > Von: "Jason Roelofs" <jameskilton / gmail.com> > > An: ruby-talk / ruby-lang.org > > Betreff: C++ Functors and Ruby extensions > > > I wonder if anyone has tried to do what I'm doing and if they've come up > > with an appropriate solution. > > > > Basic idea: > > > > struct ruby_func_wrapper > > { > > VALUE operator()(VALUE self, VALUE args) > > { > > m_callback(args ...); > > } > > } > > > > extern "C" > > void Init_functor_test() { > > ruby_func_wrapper functor; > > [ ... code that sets callback of functor ... ] > > > > rb_define_global_function("functor_test", [something here &functor], > > -2); > > } > > > > Basically, I want to use instances of the ruby_func_wrapper functor as > > callback for Ruby methods. I'm using Boost right now, and have tried > > Boost.Function and Boost.Bind to no avail (the code compiles but the > > actual > > call causes a seg fault, I assume the memory location is voided after > the > > init is done, so trying to pass execution to a bad memory location, but > > I'm > > not sure). For the record, I am trying my hand at a Boost.Ruby library. > > > > I'm also wondering if there is another way to add methods to Kernel or > > Classes outside of the rb_define_* methods. In Python you can do > > PyObject_SetAttr(namespace, name, PyCFunction) which is effectively (" > > namespace.name unction"). I've yet to find an equivalent in Ruby. > > > > I hope this is clear, though if not I can post the full code I've got > > right > > now. > > > > Thanks > > > > Jason > > Dear Jason, > > I think SWIG (http://www.swig.org/) may have a solution > for what you want to do: > > > http://www.goto.info.waseda.ac.jp/~fukusima/ruby/swig-examples/funcptr/index.html<http://www.goto.info.waseda.ac.jp/%7Efukusima/ruby/swig-examples/funcptr/index.html> > > Here's some more information on how to use it in conjunction with > Ruby : > > http://www.swig.org/Doc1.3/Ruby.html > > Best regards, > > Axel > > -- > GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS. > Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail > > ------ art_10057_29124415.1198605304976--