# Embed applicaiton INSIDE ruby

**URL:** <https://rubytalk.org/t/embed-applicaiton-inside-ruby/4620>\
**Category:** ruby-talk\
**Created:** [10 February 2003 01:32 UTC](https://rubytalk.org/t/embed-applicaiton-inside-ruby/4620 "2003-02-10T01:32:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hhcnyc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Hhcnyc](https://rubytalk.org/u/Hhcnyc)\
**Post date:** [10 February 2003 01:32 UTC](https://rubytalk.org/t/embed-applicaiton-inside-ruby/4620/1 "2003-02-10T01:32:53Z")

</div>

Call me wierd. I just wonder how could one embed the other application  
inside Ruby code. To be exact, if I have used Ruby/Tk to build  
an user interface, how do I embed the application side the Ruby interface?  
( assuming the other application also has its own interface)

Use Microsoft Windows system as an example.(yack… but what can I do)

Thanks.

HH

---

<div class="post-metadata">

**Author:** ![Lyle\_Johnson6](https://avatars.discourse-cdn.com/v4/letter/l/bb73d2/32.png) [@Lyle\_Johnson6](https://rubytalk.org/u/Lyle_Johnson6)\
**Post date:** [10 February 2003 13:14 UTC](https://rubytalk.org/t/embed-applicaiton-inside-ruby/4620/2 "2003-02-10T13:14:03Z")

</div>

hhcNYC wrote:

> Call me wierd. I just wonder how could one embed the other application  
> inside Ruby code. To be exact, if I have used Ruby/Tk to build  
> an user interface, how do I embed the application side the Ruby interface?  
> ( assuming the other application also has its own interface)

You create a Ruby extension module for it. Usually, when people talk  
about “embedding” they’re referring to embedding a Ruby interpreter into  
some other application. In contrast, “extending” Ruby refers to writing  
C/C++ code that Ruby can import at runtime and use just like native Ruby  
code.

For more information, see the “Extending Ruby” chapter in Programming Ruby:

```
http://www.rubycentral.com/book/ext_ruby.html

```

Hope this helps,

Lyle

---

<div class="post-metadata">

**Author:** ![Mark\_Probert5](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Mark\_Probert5](https://rubytalk.org/u/Mark_Probert5)\
**Post date:** [10 February 2003 16:14 UTC](https://rubytalk.org/t/embed-applicaiton-inside-ruby/4620/3 "2003-02-10T16:14:32Z")

</div>

Hi.

[hhcNYC@yahoo.com](mailto:hhcNYC@yahoo.com) (hhcNYC) did say …

> Call me wierd. I just wonder how could one embed the other application  
> inside Ruby code. To be exact, if I have used Ruby/Tk to build  
> an user interface, how do I embed the application side the Ruby  
> interface? ( assuming the other application also has its own  
> interface)

There are a number of ways that you could go about doing this:

1. Write the application in C and then write a Ruby extension  
to interface to the code (this is covered in the Pickaxe  
book).

2. Take an existing API from the other application and use a  
toolkit like SWIG ([www.swig.org](http://www.swig.org)) to write the Ruby interface  
for you (like (1) except more automated).

3. Embed a language interpreter within Ruby that isn’t ruby, and  
write your application in that language (like the ratlast  
system that I wrote that handles a FORTH-like language, or  
REXML et al that handles XML).

4. Roll your own language interpreter using a parser-scanner  
(ryacc/rlex, ralli, etc.) and then go from there.

There are probably others that brighter minds than mine can  
think of … The easiest way is probably (2) though YMMV 😉

Regards,

> **···**
>
> –  
> -mark.
> 
> * * *
> 
> ## Mark Probert probertm@NOSPAM\_nortelnetworks.com Nortel Networks ph. (613) 768-1082
> 
> All opinions expressed are my own and do not  
> reflect in any way those of Nortel Networks.

---

<div class="post-metadata">

**Author:** ![Hhcnyc](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Hhcnyc](https://rubytalk.org/u/Hhcnyc)\
**Post date:** [11 February 2003 18:39 UTC](https://rubytalk.org/t/embed-applicaiton-inside-ruby/4620/4 "2003-02-11T18:39:53Z")

</div>

Thanks to you all!

HH
