views:

3328

answers:

4

What's the best way to embed Ruby as a scripting language in C++? Using ruby.h? SWIG? Something else? What I need is to expose some C++ objects to Ruby and have the Ruby interpreter evaluate scripts that access these objects. I don't care about extending Ruby or accessing it in C++.

I've found this article on embedding Ruby in C++, and while it's very useful, it's kinda old and I was wondering if there are any other resources on the subject (or open source implementations of similar engines).

+2  A: 

swig is probablly the way to go..... but ruby doesnt embed too well......

if you want a language that embeds nicely into C++, try lua

Keith Nicholas
I did try lua, it's a wonderful language and was pretty easy to embed. Ruby is a requirement however, as I already have a lot of existing Ruby code I'd like to reuse.
Firas Assaad
then swig is pretty good..... and don't try multi threading!
Keith Nicholas
Yes even don#t try to embedd ruby and use it from a single thread in you multithreaded apps. They (the ruby programs) are changing signal handlers, envionrment variables, current directories etc. all the time.
Lothar
+5  A: 

Rice is looking very promising.

Avdi
Note to Windows users: Rice is only known to properly compile and run under Cygwin and Mingw. :(
Firas Assaad
+3  A: 

Ruby provides a very helpful README.EXT file. It has lots of information about how to extend Ruby, and convert between C & Ruby types.

There is also this excerpt from the pick axe book which pretty much covers the same thing.

In my case, when I added Ruby scripting to my application I decided against using swig, because my needs were very simple, and I didn't want to add yet another build dependency.

hyperlogic
+1  A: 

You might wish to check out tinyrb.

oylenshpeegul