What's the best way to mix Ruby and other languages? (Especially C++)
I'm learning Ruby, and I'm starting to play with building extensions in C. I have Programming Ruby The Pragmatic Programmers' Guide and so I can follow that for the basic nuts and bolts. What I was wondering is if there already existed some nifty frameworks/开发者_JAVA技巧whatever to help interoperability between Ruby and other languages, with C++ being the most important for me. I've tried googling, but the results focus on language comparisons, rather than language interoperability.
TIA,
Andy
Take a look at SWIG. It's a nice framework for integrating C and C++ programs with other programs written in higher level languages. It was originally written to support Python, TCL, and Perl, but has been expanded to support Ruby as well.
If you want to use Ruby with Java, then look into JRuby. It is a Java implementation of Ruby and allows you to call Java libraries/code through Ruby.
http://jruby.org/
FFI is the recommended way to hook Ruby implementations up to C libraries, but a bit of Googling suggests that this probably won't work as-is with C++, so try SWIG. There's an FFI-SWIG thing here.
精彩评论