# Embedded Ruby

**URL:** <https://www.ruby-forum.com/t/embedded-ruby/155972>\
**Category:** Ruby\
**Created:** [December 18, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/embedded-ruby/155972 "2008-12-18T18:54:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rolando\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d9b06d/32.png) [@Rolando\_A](https://www.ruby-forum.com/u/Rolando_A)\
**Post date:** [December 18, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/embedded-ruby/155972/1 "2008-12-18T18:54:57Z")

</div>

Hello all,  
I’m trying to embedd ruby, so far this is what I have:

ruby\_init();  
ruby\_init\_loadpath();  
ruby\_script(“embedded”);  
rb\_load\_file(“my\_script.rb”);  
ruby\_run();  
/\* 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,

---

<div class="post-metadata">

**Author:** ![Rolando\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d9b06d/32.png) [@Rolando\_A](https://www.ruby-forum.com/u/Rolando_A)\
**Post date:** [December 18, 2008, 7:10pm UTC](https://www.ruby-forum.com/t/embedded-ruby/155972/2 "2008-12-18T19:10:10Z")

</div>

On Fri, Dec 19, 2008 at 02:46:12AM +0900, Rolando A. wrote:

> 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?

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

---

<div class="post-metadata">

**Author:** ![Rolando\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d9b06d/32.png) [@Rolando\_A](https://www.ruby-forum.com/u/Rolando_A)\
**Post date:** [December 18, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/embedded-ruby/155972/3 "2008-12-18T19:11:56Z")

</div>

nevermind, rb\_eval\_string suits my needs 😛

On Dec 18, 2008, at 2:46 PM, Rolando A. wrote:

> 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,
