# Embedded Ruby

**URL:** <https://rubytalk.org/t/embedded-ruby/50799>\
**Category:** ruby-talk\
**Created:** [18 December 2008 17:46 UTC](https://rubytalk.org/t/embedded-ruby/50799 "2008-12-18T17:46:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rolando\_Abarca](https://avatars.discourse-cdn.com/v4/letter/r/5daacb/32.png) [@Rolando\_Abarca](https://rubytalk.org/u/Rolando_Abarca)\
**Post date:** [18 December 2008 17:46 UTC](https://rubytalk.org/t/embedded-ruby/50799/1 "2008-12-18T17:46:12Z")

</div>

Hello all,  
I'm trying to embedd ruby, so far this is what I have:  
&nbsp;&nbsp;  
&nbsp;&nbsp;ruby\_init();  
&nbsp;&nbsp;ruby\_init\_loadpath();  
&nbsp;&nbsp;ruby\_script("embedded");  
&nbsp;&nbsp;rb\_load\_file("my\_script.rb");  
&nbsp;&nbsp;ruby\_run();  
&nbsp;&nbsp;/\* rest of my app here \*/

However, ruby is taking control of my code after calling ruby\_run, since it will always call "exit" after executing the code... is there a way to not exit after executing the ruby code?

thanks a lot,

> **···**
>
> --  
> Rolando Abarca M.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Hinegardner](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Jeremy\_Hinegardner](https://rubytalk.org/u/Jeremy_Hinegardner)\
**Post date:** [18 December 2008 18:01 UTC](https://rubytalk.org/t/embedded-ruby/50799/2 "2008-12-18T18:01:48Z")

</div>

This is by design ruby\_run() does not return. I imagine what you want to do is  
execute your script via rb\_protect(). You could take a look at  
[ruby embedded into c++](http://metaeditor.sourceforge.net/embed/) althought it is embedding ruby in C++  
much of what it talks about works for C.

How vim embedds ruby is good code to read too. Download the vim source  
code and look at if\_ruby.c

enjoy,

-jeremy

> **···**
>
> On Fri, Dec 19, 2008 at 02:46:12AM +0900, Rolando Abarca wrote:
> 
> > Hello all,  
> > I'm trying to embedd ruby, so far this is what I have:  
> > &nbsp;&nbsp;  
> > &nbsp;&nbsp;ruby\_init();  
> > &nbsp;&nbsp;ruby\_init\_loadpath();  
> > &nbsp;&nbsp;ruby\_script("embedded");  
> > &nbsp;&nbsp;rb\_load\_file("my\_script.rb");  
> > &nbsp;&nbsp;ruby\_run();  
> > &nbsp;&nbsp;/\* rest of my app here \*/
> > 
> > However, ruby is taking control of my code after calling ruby\_run, since it  
> > will always call "exit" after executing the code... is there a way to not  
> > exit after executing the ruby code?
> 
> # --
> 
> Jeremy Hinegardner jeremy@hinegardner.org

---

<div class="post-metadata">

**Author:** ![Rolando\_Abarca](https://avatars.discourse-cdn.com/v4/letter/r/5daacb/32.png) [@Rolando\_Abarca](https://rubytalk.org/u/Rolando_Abarca)\
**Post date:** [18 December 2008 18:03 UTC](https://rubytalk.org/t/embedded-ruby/50799/3 "2008-12-18T18:03:29Z")

</div>

nevermind, rb\_eval\_string suits my needs 😛

> **···**
>
> On Dec 18, 2008, at 2:46 PM, Rolando Abarca wrote:
> 
> > Hello all,  
> > I'm trying to embedd ruby, so far this is what I have:  
> > &nbsp;&nbsp;  
> > &nbsp;&nbsp;ruby\_init();  
> > &nbsp;&nbsp;ruby\_init\_loadpath();  
> > &nbsp;&nbsp;ruby\_script("embedded");  
> > &nbsp;&nbsp;rb\_load\_file("my\_script.rb");  
> > &nbsp;&nbsp;ruby\_run();  
> > &nbsp;&nbsp;/\* rest of my app here \*/
> > 
> > However, ruby is taking control of my code after calling ruby\_run, since it will always call "exit" after executing the code... is there a way to not exit after executing the ruby code?
> > 
> > thanks a lot,
> 
> regards,  
> --  
> Rolando Abarca M.
