# Using ruby in place of C

**URL:** <https://rubytalk.org/t/using-ruby-in-place-of-c/34465>\
**Category:** ruby-talk\
**Created:** [15 January 2007 11:43 UTC](https://rubytalk.org/t/using-ruby-in-place-of-c/34465 "2007-01-15T11:43:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Finch](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Chris\_Finch](https://rubytalk.org/u/Chris_Finch)\
**Post date:** [15 January 2007 11:43 UTC](https://rubytalk.org/t/using-ruby-in-place-of-c/34465/1 "2007-01-15T11:43:28Z")

</div>

Hi all,  
This may be silly question but:

There is a program that I want to use that says:  
"there is a C interface provided so that user codes can be written in C  
or C++."

What I want to know is if I can write these "user codes" in ruby  
instead?

Chris.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Dido\_Sevilla](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@Dido\_Sevilla](https://rubytalk.org/u/Dido_Sevilla)\
**Post date:** [15 January 2007 11:50 UTC](https://rubytalk.org/t/using-ruby-in-place-of-c/34465/2 "2007-01-15T11:50:09Z")

</div>

But you will have to work at writing a Ruby extension in C that uses  
the published C interface first. If you intend to use the program from  
Ruby a lot, it will make a lot of sense to do so.

> **···**
>
> On 1/15/07, Chris Finch \<christopher.finch@nuth.nhs.uk\> wrote:
> 
> > Hi all,  
> > This may be silly question but:
> > 
> > There is a program that I want to use that says:  
> > "there is a C interface provided so that user codes can be written in C  
> > or C++."
> > 
> > What I want to know is if I can write these "user codes" in ruby  
> > instead?

---

<div class="post-metadata">

**Author:** ![Bira](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@Bira](https://rubytalk.org/u/Bira)\
**Post date:** [15 January 2007 11:57 UTC](https://rubytalk.org/t/using-ruby-in-place-of-c/34465/3 "2007-01-15T11:57:12Z")

</div>

You can. There's a program called SWIG that can "wrap" a C interface  
so that it can be called from Ruby. You would have to do that first,  
but then you could use this interface as if it were any other Ruby  
library.

> **···**
>
> On 1/15/07, Chris Finch \<christopher.finch@nuth.nhs.uk\> wrote:
> 
> > Hi all,  
> > This may be silly question but:
> > 
> > There is a program that I want to use that says:  
> > "there is a C interface provided so that user codes can be written in C  
> > or C++."
> > 
> > What I want to know is if I can write these "user codes" in ruby  
> > instead?
> 
> --  
> Bira
> 
> > **[Computaria Explícita](http://compexplicita.blogspot.com)**
> >
> > I know it hurts. Try not to think.
> 
> [http://sinfoniaferida.blogspot.com](http://sinfoniaferida.blogspot.com)

---

<div class="post-metadata">

**Author:** ![Marc\_Heiler](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Marc\_Heiler](https://rubytalk.org/u/Marc_Heiler)\
**Post date:** [15 January 2007 15:26 UTC](https://rubytalk.org/t/using-ruby-in-place-of-c/34465/4 "2007-01-15T15:26:09Z")

</div>

What are "user codes"?

Anyway, if you can EXTEND it in C, you can use Ruby-C as well as  
easily, and afterwards use pure Ruby. Not sure if that will  
work in your case, I dont know what "user codes" are 🙂

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
