From: Jason Roelofs Date: 2007-12-25T04:02:38+09:00 Subject: C++ Functors and Ruby extensions ------=_Part_8457_12242682.1198522956453 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 = function"). 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 ------=_Part_8457_12242682.1198522956453--