On Dec 24, 4:02 pm, Jason Roelofs <jameskil... / gmail.com> wrote: > 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. > Your assumption is correct. You can't do it. The functor needs to remain visible in memory. Also, depending on your compiler, the way C+ + functions expect arguments may be different from what ruby expects in its C API (this is usually a problem with Windows' __stdcall vs. __fastcall, etc). You will also not get ANY speed benefit from using a functor, thou, so using it is kind of pointless. > 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. No. class A def f; end end repeat as many times as needed. Classes are open in ruby. rb_define_* do just the above and is equivalent to python's adding of functions. Overall, as the other poster said, you should use SWIG. There's really no benefit to using a C++ approach to wrapping code like Boost.Python does. If anything, Boost.Python is much more primitive than what swig can do.