# Intro to embedded Ruby

**URL:** <https://www.ruby-forum.com/t/intro-to-embedded-ruby/60088>\
**Category:** Ruby\
**Created:** [May 10, 2006, 2:35am UTC](https://www.ruby-forum.com/t/intro-to-embedded-ruby/60088 "2006-05-10T02:35:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![akrasia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cab0a1/32.png) [@akrasia](https://www.ruby-forum.com/u/akrasia)\
**Post date:** [May 10, 2006, 2:35am UTC](https://www.ruby-forum.com/t/intro-to-embedded-ruby/60088/1 "2006-05-10T02:35:24Z")

</div>

Hello all!

I’m relatively new to the world of Ruby, but I feel I’m catching on  
quickly to the advantages and conveniences that the language offers.  
Mostly, I’ve been using it to develop games.

A recent interest of mine involves using Ruby and C/C++ together to  
handle a more complex game. My goal is to have C/C++ handle all of the  
graphics via SDL or something similar and have Ruby handle all of the  
game logic (input, script handling, and such).

Essentially, I’m looking for a basic, from-the-ground-up introduction to  
embedding Ruby in C/C++. I’ve had much experience with C/C++ and  
programming overall and I am using Linux for development.

Thanks!

---

<div class="post-metadata">

**Author:** ![akrasia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cab0a1/32.png) [@akrasia](https://www.ruby-forum.com/u/akrasia)\
**Post date:** [May 10, 2006, 2:56am UTC](https://www.ruby-forum.com/t/intro-to-embedded-ruby/60088/2 "2006-05-10T02:56:32Z")

</div>

From: “akrasia” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> A recent interest of mine involves using Ruby and C/C++ together to  
> handle a more complex game. My goal is to have C/C++ handle all of the  
> graphics via SDL or something similar and have Ruby handle all of the  
> game logic (input, script handling, and such).
> 
> Essentially, I’m looking for a basic, from-the-ground-up introduction to  
> embedding Ruby in C/C++. I’ve had much experience with C/C++ and  
> programming overall and I am using Linux for development.

Hi,

Not quite what you asked, but you might want to check out Gosu’s  
Ruby bindings: [http://www.raschke.de/julian/gosu/](http://www.raschke.de/julian/gosu/)

Since Ruby / Gosu is a C++ library providing input handling as well as  
graphics, etc., and it has Ruby bindings to make the C++ library also  
available from ruby, this may provide you with good embedding  
examples.

Here’s a recent post from Florian G. about a game written in Ruby /  
Gosu,  
running on Win32 / OS X / Linux:  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/187832](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/187832)

Screenshot: [http://flgr.0x42.net/gdc72h-05/final.jpg](http://flgr.0x42.net/gdc72h-05/final.jpg)

Hope this helps,

Bill

---

<div class="post-metadata">

**Author:** ![akrasia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cab0a1/32.png) [@akrasia](https://www.ruby-forum.com/u/akrasia)\
**Post date:** [May 10, 2006, 5:26am UTC](https://www.ruby-forum.com/t/intro-to-embedded-ruby/60088/3 "2006-05-10T05:26:17Z")

</div>

I don’t know anything about game programming so this may not be useful  
to  
you. I’ve tried embedding both ways (Ruby in C++, C++ in Ruby), and I  
think  
it’s much better to call native code from Ruby. You could look at the  
dlopen  
library, which is really rather good but lightly documented and somewhat  
frustrating. But you might have better luck writing “extensions” in C++.  
Read the file README.EXT in the Ruby distro, and then read the source  
code  
for some of the standard extensions in the distro. With an extension you  
can  
basically write Ruby in C++, create your own Ruby classes, etc.

---

<div class="post-metadata">

**Author:** ![akrasia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cab0a1/32.png) [@akrasia](https://www.ruby-forum.com/u/akrasia)\
**Post date:** [May 10, 2006, 2:42pm UTC](https://www.ruby-forum.com/t/intro-to-embedded-ruby/60088/4 "2006-05-10T14:42:56Z")

</div>

On May 10, 2006, at 1:39 AM, Sam R. wrote:

> I’m a huge fan of ruby, I use it whenever I can, but not for  
> everything.

Blasphemy! Burn him! Burn him! 😉

---

<div class="post-metadata">

**Author:** ![akrasia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cab0a1/32.png) [@akrasia](https://www.ruby-forum.com/u/akrasia)\
**Post date:** [May 10, 2006, 7:39am UTC](https://www.ruby-forum.com/t/intro-to-embedded-ruby/60088/5 "2006-05-10T07:39:50Z")

</div>

Quoting removed\_email\_address@domain.invalid, on Wed, May 10, 2006 at 09:35:35AM +0900:

> Hello all!
> 
> I’m relatively new to the world of Ruby, but I feel I’m catching on  
> quickly to the advantages and conveniences that the language offers.  
> Mostly, I’ve been using it to develop games.
> 
> A recent interest of mine involves using Ruby and C/C++ together to  
> handle a more complex game. My goal is to have C/C++ handle all of the  
> graphics via SDL or something similar and have Ruby handle all of the  
> game logic (input, script handling, and such).

I’m a huge fan of ruby, I use it whenever I can, but not for everything.

You might want to look at lua. It allows multiple independent script  
contexts (instead of process-global context like ruby), is pretty fast,  
has a rich enough language, though is really poor in library support.  
I’d never use it as a stand-alone language, but I’ve been really liking  
it as an embedded-into-C/C++ scripting language. Also, its apparently  
used for a LOT of game developement.

Cheers,  
Sam
