Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Cooperation between the C++ and Ruby sides of Gosu?
- By timmcd Date 2009-07-12 01:27
I have a friend who is hooked on C++. C++, however, makes me gag. We'd both like to use Gosu. Would we have to embed Ruby in C++, or is there a simpler way for us to cooperate here? Or would it really be the simplest to just embed? If so, can anyone show me how to?
- By Maverick Date 2009-07-12 05:52
Why does C++ wanna make you gag? I like Ruby AND C++ ( It is possible! ) There are pros and cons to all languages.
I'd suggest either fighting to the death about it, blackmail your friend to use Ruby, or one of you suck it up and learn new language.

Nah. That's a dumb idea, just beat him up.


OK. Seriously, I would firstly suggest you make very small games in C++ and then make the exact same game in Ruby and continue doing that. When it comes to bigger games, swap it out. One big game write it in C++ and the next one use Ruby. With two people into making games with different -awesome- languages, you could teach each other and become awesome as well. Both of you should be open minded about new languages. They're all fun to learn ( though daunting at first ) and having more than one programming language background will get you far.

I wish I had a friend who was into making games where I lived. That'd be sweet. Anyway I hope I helped. Hope to see you more active here! ( It's a totally rad place to be. Julian is a party animal here. And I won't get started with philomory. ) :p
- By jlnr (dev) Date 2009-07-12 13:46 Edited 2009-07-12 13:48
I'm almost out of wisdom to add to this thread :D, buuut...

To embed Ruby, your C++ project would need to be built against ruby.h and the ruby-msvc-something library that come with the One-Click Ruby installers. For Ruby 1.8, it should be enough to follow these steps:
You could use rb_eval_string() for everything, first ot load all your Ruby files, then to call "on_player_hits_a_wall" etc... To get values back out of these functions, you need to cast the returned VALUE into something useful, google for functions/macros from ruby.h like NUM2INT or FIX2LONG or STR2CSTR. It works a bit differently with Ruby 1.9.

The other, usually suggested route would be to write the game in Ruby/Gosu, but letting your friend write all the performance critical data structures and algorithms (pathfinding etc.) in C++. Then he can make these available to you by wrapping them with either Rice, SWIG or a ruby-ffi binding.

I have no idea how you'd share Gosu resources with the language that is embedded in either case. My only idea (for the first route) would be to slap the RubyGosu_wrap.cxx file into your C++ project and call Init_gosu after you have initialized your embedded Ruby. That should give it access to the same version of Gosu that is built into the C++ program. Then you will probably have to use some weird, SWIG-generated function to wrap Gosu::Image references into a Ruby VALUE so you can pass it to Ruby functions. If anyone knows how to do this, then it's the SWIG docs ;)

Never done it, never seen it done, but if it works for you then please post how :)
Up Topic Gosu / Gosu Exchange / Cooperation between the C++ and Ruby sides of Gosu?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill