Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've been discussing a conceptual project with a friend of mine and the the most effective way we've seen of doing it is writing the engine in C++ while the logic would be done in Ruby.
However, we would need data to be passed around often, for example:

  • Engine reports that A happened, that gets triggered in a proc array (event "A" is passed but proc doesnt use it)
  • Ruby decides that we need to wait for B to happen
  • Ruby adds a proc to an array. The array of procs is iterated during each cycle in the C++ engine
  • C++ engine reports that B happened and passes "event B (should be a ruby object)
  • Ruby receives event B and decides what to do next

I don't work with multiple languages often, and was wondering if it's possible to implement things in this way. I know that there's the ruby VALUE in C++, but would like to know the standard way of combining the two. (of course I know ruby follows the perl "more than 1 way to do it", but there's often a standardized way)

Edit 1: I've ran a quick test with SWIG and met a problem really fast. From what I can see, ruby (1.9.3p286, though it uses the 1.9.1 gems afaik) can't load the shared object. I've put the code, actions done and more information here.

Edit 2: Tried compiling to latest ruby and swig version (god, I love ABS) to see if maybe it was some compile error upstream. I got no errors and problem remains. Seems it might be an incompatibility between this SWIG version and Ruby version... Or a problem with the current Ruby version.

share|improve this question
2  
Take a look at SWIG. –  Yannis Rizos Nov 4 '12 at 2:19
    
@YannisRizos I've seen SWIG but it seems very inelegant and passing values would be difficult, wouldn't it? –  Shingetsu Nov 4 '12 at 16:26

1 Answer 1

Swig is the way to go. The data passing is also possible there in my understanding with typemaps. Have a look at it.

Also look at some helpful links below

share|improve this answer
    
I've read SWIG and Extending Ruby, both of which failed (see the two edits). Thanks for the rice link, I'll take a look at it and accept answer if it works. –  Shingetsu Nov 5 '12 at 13:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.