c++ruby

Extending Ruby with C++?


Is there any way to pass Ruby objects to a C++ application ? I have never done that kind of thing before and was wondering if that would be possible. Would it require to modify the Ruby core code ?


Solution

  • Yes, and no, respectively.

    Ruby is written in C. C++ is, by design, C-compatible.

    All objects in Ruby are held by a VALUE object (which is a union type), which can be passed around quite easily.

    Any directions you find for extending Ruby with C apply in C++ with little modification. Alternatively, you can use something like SWIG to simplify writing your extensions.