# Calling Ruby from C/C++

**URL:** <https://rubytalk.org/t/calling-ruby-from-c-c/51051>\
**Category:** ruby-talk\
**Created:** [8 January 2009 18:04 UTC](https://rubytalk.org/t/calling-ruby-from-c-c/51051 "2009-01-08T18:04:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_Tibs](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@Mr\_Tibs](https://rubytalk.org/u/Mr_Tibs)\
**Post date:** [8 January 2009 18:04 UTC](https://rubytalk.org/t/calling-ruby-from-c-c/51051/1 "2009-01-08T18:04:44Z")

</div>

Hi,

Is there a way to execute Ruby code from C/C++? I know it is possible  
to call Tcl code from C/C++; the Tcl library provides a  
Tcl\_CreateInterp() function which creates an in-process interpreter  
running the Tcl code. Does Ruby provide something similar?

I cannot use any system() or forking functions.

Thanks,  
Tiberiu

---

<div class="post-metadata">

**Author:** ![Mohit\_Sindhwani1](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mohit\_Sindhwani1](https://rubytalk.org/u/Mohit_Sindhwani1)\
**Post date:** [8 January 2009 18:10 UTC](https://rubytalk.org/t/calling-ruby-from-c-c/51051/2 "2009-01-08T18:10:05Z")

</div>

Mr\_Tibs wrote:

> Hi,
> 
> Is there a way to execute Ruby code from C/C++? I know it is possible  
> to call Tcl code from C/C++; the Tcl library provides a  
> Tcl\_CreateInterp() function which creates an in-process interpreter  
> running the Tcl code. Does Ruby provide something similar?  
> &nbsp;&nbsp;

Yes it does. Search up "ruby c c++" (without quotes) in Google.

Also, see - [http://whytheluckystiff.net/ruby/pickaxe/html/ext\_ruby.html](http://whytheluckystiff.net/ruby/pickaxe/html/ext_ruby.html)

Cheers,  
Mohit.  
1/9/2009 | 2:09 AM.

---

<div class="post-metadata">

**Author:** ![Mr\_Tibs](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@Mr\_Tibs](https://rubytalk.org/u/Mr_Tibs)\
**Post date:** [8 January 2009 18:24 UTC](https://rubytalk.org/t/calling-ruby-from-c-c/51051/3 "2009-01-08T18:24:43Z")

</div>

It seems that everything I find on the web is about calling C from  
Ruby (which is C extensions). I need to do call Ruby from C.

---

<div class="post-metadata">

**Author:** ![Mohit\_Sindhwani1](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mohit\_Sindhwani1](https://rubytalk.org/u/Mohit_Sindhwani1)\
**Post date:** [8 January 2009 18:44 UTC](https://rubytalk.org/t/calling-ruby-from-c-c/51051/4 "2009-01-08T18:44:54Z")

</div>

Mr\_Tibs wrote:

> It seems that everything I find on the web is about calling C from  
> Ruby (which is C extensions). I need to do call Ruby from C.

Perhaps, you misunderstood the pages. I asked for you to search "ruby c c++" - Please see the following:

[1] From the first hit:  
[http://metaeditor.sourceforge.net/embed/](http://metaeditor.sourceforge.net/embed/)  
In this document I will descripe how to embed the ruby interpreter into c++ [WhyEmbedRuby?, EmbedRuby] and provide you with a skeleton you easily can build upon.

[2] The URL I sent: [http://whytheluckystiff.net/ruby/pickaxe/html/ext\_ruby.html](http://whytheluckystiff.net/ruby/pickaxe/html/ext_ruby.html)  
Please scroll down the page till you find 'Embedding a Ruby Interpreter'

and so on.

You could also search up 'embed ruby c c++'

Cheers,  
Mohit.  
1/9/2009 | 2:45 AM.

---

<div class="post-metadata">

**Author:** ![Mr\_Tibs](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@Mr\_Tibs](https://rubytalk.org/u/Mr_Tibs)\
**Post date:** [8 January 2009 19:04 UTC](https://rubytalk.org/t/calling-ruby-from-c-c/51051/5 "2009-01-08T19:04:45Z")

</div>

Coo. Thanks. I don't know how I missed that.

---

<div class="post-metadata">

**Author:** ![Mohit\_Sindhwani1](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mohit\_Sindhwani1](https://rubytalk.org/u/Mohit_Sindhwani1)\
**Post date:** [8 January 2009 19:19 UTC](https://rubytalk.org/t/calling-ruby-from-c-c/51051/6 "2009-01-08T19:19:49Z")

</div>

Mr\_Tibs wrote:

> Coo. Thanks. I don't know how I missed that.  
> &nbsp;&nbsp;

It's easy to miss it 🙂

Hope this helps.

Cheers,  
Mohit.  
1/9/2009 | 3:19 AM.

> **···**
>
> >
