# Using Ruby as a scripting language within a C app

**URL:** <https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166>\
**Category:** Ruby\
**Created:** [September 22, 2008, 6:03am UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166 "2008-09-22T06:03:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![forgottenwizard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@forgottenwizard](https://www.ruby-forum.com/u/forgottenwizard)\
**Post date:** [September 22, 2008, 6:03am UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166/1 "2008-09-22T06:03:34Z")

</div>

I’m working on building a MUD, and I would like to be able to use Ruby  
as the scripting language within the MUD (such as with mobiles, rooms,  
objects, ect).

I would like someone to give me an idea on how to do this, as well as an  
idea on how much effort and time this will require.

---

<div class="post-metadata">

**Author:** ![forgottenwizard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@forgottenwizard](https://www.ruby-forum.com/u/forgottenwizard)\
**Post date:** [September 22, 2008, 9:49am UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166/2 "2008-09-22T09:49:19Z")

</div>

forgottenwizard wrote:

> I’m working on building a MUD, and I would like to be able to use Ruby  
> as the scripting language within the MUD (such as with mobiles, rooms,  
> objects, ect).
> 
> I would like someone to give me an idea on how to do this, as well as an  
> idea on how much effort and time this will require.

[http://poignantguide.net/ruby/chapter-6.html](http://poignantguide.net/ruby/chapter-6.html)

Scroll down to “A Sponsored Dragon-Slaying” and enjoy.

---

<div class="post-metadata">

**Author:** ![forgottenwizard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@forgottenwizard](https://www.ruby-forum.com/u/forgottenwizard)\
**Post date:** [September 22, 2008, 10:55am UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166/3 "2008-09-22T10:55:02Z")

</div>

forgottenwizard wrote:

> I’m working on building a MUD, and I would like to be able to use Ruby  
> as the scripting language within the MUD (such as with mobiles, rooms,  
> objects, ect).

If you are using C/C++ (or indeed C#) in .NET you can embed Ruby  
programs using our free Ruby Connector:

[http://www.sapphiresteel.com/SapphireSteel-Downloads](http://www.sapphiresteel.com/SapphireSteel-Downloads)

For some ideas on writing adventure type games in Ruby, you may find my  
Ruby adventure game tutorial of use:

[http://www.bitwisemag.com/2/Adventures-In-Ruby](http://www.bitwisemag.com/2/Adventures-In-Ruby)  
[http://www.bitwisemag.com/2/Adventures-In-Ruby-Part-2](http://www.bitwisemag.com/2/Adventures-In-Ruby-Part-2)  
[http://www.bitwisemag.com/2/Adventures-In-Ruby-Part-3](http://www.bitwisemag.com/2/Adventures-In-Ruby-Part-3)

best wishes  
Huw C.

SapphireSteel Software  
Ruby and Rails In Visual Studio  
[http://www.sapphiresteel.com](http://www.sapphiresteel.com)

---

<div class="post-metadata">

**Author:** ![forgottenwizard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@forgottenwizard](https://www.ruby-forum.com/u/forgottenwizard)\
**Post date:** [September 22, 2008, 11:07pm UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166/4 "2008-09-22T23:07:09Z")

</div>

Ken B. wrote:

> On Mon, 22 Sep 2008 02:41:12 -0500, Brian C. wrote:
> 
> > Scroll down to “A Sponsored Dragon-Slaying” and enjoy.  
> > Aside from being entertaining, what does this have to do with embedding  
> > Ruby in a C-based MUD engine?

OK, I missed the smiley,

 tag etc.

For a more useful link, see  
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext\_ruby.html](http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html)

The section “Embedding a Ruby Interpreter” is brief, but much of the  
preceding stuff about VALUE and so on is relevant. There’s enough to get  
started with experimenting anyway.

In any case, a simple Google for “embedded ruby” turns up a bunch of  
useful stuff. The first hit is [ruby embedded into c++](http://metaeditor.sourceforge.net/embed/)

None of that is specific to the problem domain of MUDs (apart from  
\_why’s page), but once you have an embedded ruby interpreter, what you  
do with it is up to you.

I’d question why you’d want to write any of the rest of it in C, but  
that’s a different issue 🙂

---

<div class="post-metadata">

**Author:** ![forgottenwizard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@forgottenwizard](https://www.ruby-forum.com/u/forgottenwizard)\
**Post date:** [September 22, 2008, 10:40pm UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166/5 "2008-09-22T22:40:54Z")

</div>

On Mon, 22 Sep 2008 02:41:12 -0500, Brian C. wrote:

> Scroll down to “A Sponsored Dragon-Slaying” and enjoy.  
> Aside from being entertaining, what does this have to do with embedding  
> Ruby in a C-based MUD engine?

–Ken

---

<div class="post-metadata">

**Author:** ![forgottenwizard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@forgottenwizard](https://www.ruby-forum.com/u/forgottenwizard)\
**Post date:** [September 23, 2008, 10:03pm UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166/6 "2008-09-23T22:03:46Z")

</div>

> I’d question why you’d want to write any of the rest of it in C, but  
> that’s a different issue 🙂

I am not the original author, but personally I always enjoy it when  
people do not ask why I want to do something that way, but rather help  
how i do it.

In my experience way too often people who tried to ask for the why also  
tried to persuade me that the way is wrong. Which may be fine but it  
wastes my time as well in like 95% of the cases I personally experienced  
and does not really help me as well. 😉

---

<div class="post-metadata">

**Author:** ![forgottenwizard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@forgottenwizard](https://www.ruby-forum.com/u/forgottenwizard)\
**Post date:** [September 23, 2008, 8:15am UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166/7 "2008-09-23T08:15:40Z")

</div>

On 05:58 Tue 23 Sep, Brian C. wrote:

> [Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html)  
> do with it is up to you.
> 
> ## I’d question why you’d want to write any of the rest of it in C, but that’s a different issue 🙂
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

I’m starting off of an existing codebase, and trying to rewrite it into  
Ruby seems like a waste.

---

<div class="post-metadata">

**Author:** ![forgottenwizard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@forgottenwizard](https://www.ruby-forum.com/u/forgottenwizard)\
**Post date:** [September 24, 2008, 5:02am UTC](https://www.ruby-forum.com/t/using-ruby-as-a-scripting-language-within-a-c-app/149166/8 "2008-09-24T05:02:50Z")

</div>

On Tuesday 23 September 2008 15:03:42 Marc H. wrote:

> > I’d question why you’d want to write any of the rest of it in C, but  
> > that’s a different issue 🙂
> 
> I am not the original author, but personally I always enjoy it when  
> people do not ask why I want to do something that way, but rather help  
> how i do it.

There are advantages to both. Consider the hypothetical question:  
“How can I delete every file on my hard drive with a single command?”

If there’s an easy way to do what I want to do, I’d like to know it.  
“rm -rf /”

However, in the same message, it might be helpful to suggest other ways  
of  
thinking about the problem:

“Well, if you really want the data gone (to hide it), best ‘dd  
if=/dev/zero  
of=/dev/sda’. And if you only need to nuke a particular directory, you  
can ‘rm -rf /foo’ – but you may want to look up ‘shred’ first.”

I might learn something. It might even save me weeks of work – might  
stop me  
from nuking my whole hard drive, in the above (contrived) example.

If not, it doesn’t waste very much time to read them and ignore them.

So, I think Brian’s post was actually helpful in that he’s pointed out a  
few  
useful resources for embedding a Ruby interpreter, and also suggested  
that it  
might be better to write it in Ruby. (I’d second that – a MUD doesn’t  
have  
to be fast, but it’s better if it’s flexible, and it really shouldn’t  
take  
long.)
