rpattabi
rpattabi

Reputation: 10207

C/C++ within Ruby code?

C/C++ would be good option to write some of the performance critical aspects of a Ruby Application. I know this is possible.

I would like to know how to add C/C++ code into Ruby code; any other language for that matter.

Are there any practical applications of this which you noticed in open source projects or else?

Upvotes: 5

Views: 5931

Answers (6)

Adrian
Adrian

Reputation: 15171

Besides "Extending Ruby", here are two other resources:

  • README.EXT (extension.rdoc) - shows you more about how to build C extensions. A good compliment to "Extending Ruby"
  • Ruby Inline - This is a library that tries to make it easier to build C extensions by having you call methods in ruby to compile C code.

Upvotes: 9

Mark
Mark

Reputation: 108527

We use ffi in one of our projects.

Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby and JRuby.

It works quite well.

Upvotes: 2

Peter M
Peter M

Reputation: 7493

Seems like you need to read up on Extending Ruby

Upvotes: 0

peejaybee
peejaybee

Reputation: 402

Look in the "Extending Ruby" section of the Pickaxe book:

http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html

Upvotes: 5

danp
danp

Reputation: 15241

Compile your high performance code into a system service/executable, and call it from inside Ruby...?

Upvotes: 0

andyp
andyp

Reputation: 6269

you should have a look at SWIG - it allows you to create ruby extensions in C/C++.

Upvotes: 4

Related Questions