Ruby: Almost fed up

Sage
Posts: 1,482
Joined: 2002.09
Post: #1
While it's a great language and all, but it's almost completely useless for games unless you can write extensions for it. I've tried compiling the SDL and openGL extensions for it, but never could get it to recognize that I actually have the libraries installed. I finally found that they were available on FINK and tried those, they crash ruby. I can't for the life of me figure out (or even find documentation) on how to use mkmf.

Then I discovered SWIG, it sounded perfect. All I wanted was wrappers anyway. I can get things to build and link, but when I try to load the extension it crashes ruby. Even with the simplest case, a single global variable, it crashes. I've wasted so many hours trying to get something to work it's not even funny anymore.

Then I thought about pyGame, I heard people had that working on OSX, so I gave python a look. I got pyGame and even pyOpenGL to work, but good luck trying to package all of that crap up and make it a double clickable application.

It would probably help if I knew how to use GCC and Make better, but I find it hard to find any kind of documentation for these either. I've gone over some of the Make documentation and it makes sense... until you open a real makefile and your eyes glaze over. Its impossible to wade through man page for GCC, and I can't really find any "getting started" tutorials to show me how to compile and link things manually so I can understand how it works. It seems like no one writes anything on how to start with all these lower level tools because it's assumed that if you need to be using them you already know how.

END OF RANTING

I'm finding it impossible to bridge the gap between what I can do in an IDE like Xcode and Ruby because the learning curve of the underlying tools seems like a brick wall. HELP!
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #2
Sounds like a call for a Ruby Tutorial by OSC. Smile

Cheers,

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
Don't know why I didn't think about this before, but I just tried making an empty Ruby module with SWIG. Even though there was no code or anything it still crashes when you load the extension.

example.i
Code:
%module example


Commands run
Code:
swig -ruby example.i
gcc -c example_wrap.c -o example_wrap.o
gcc -bundle example_wrap.o -lruby -o example.bundle


test.rb
Code:
require 'example'

when test.rb is run, it produces this error
Code:
ruby test.rb  
test.rb:1: [BUG] Bus Error
ruby 1.6.8 (2002-12-24) [powerpc-darwin7.0]
Abort trap

If anyone can tell me what I'm doing wrong it would be very helpful.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
I really haven't messed around much with doing things the "right" way...

Check out http://onesadcookie.is-a-geek.net/svn/repos . In particular, the RubyGameCommon and RubyGameShellCommon stuff (the difference between the two is that the former uses GLUT where the latter uses GameShell, also available from the same place).

The easiest way to get the code is using subversion. If you've got fink already, grab that. Then,
svn checkout http://onesadcookie.is-a-geek.net/svn/repos OSCsCode
that'll take a while, but you get all the code up there, which is mostly game-oriented Ruby stuff.

You need ruby 1.8 installed to run RBuild, my build system. Grab it from fink, or find one of the ruby archives that's in the checkout, and ./configure && make -j3 && sudo make install that. Check that "which ruby" tells you you're using the right one...

Then cd into OSCsCode/RubyGameCommon, and type ruby ../RBuild/rbuild.rb
that'll build RubyGameCommon, which most of the rest of the samples use.

Then, for example, cd up and into MD2, and again, ruby ../RBuild/rbuild.rb -- that'll build the MD2 loader.

That should get you started -- I'm happy to explain further if necessary.
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #5
For your Python troubles I would suggest #macpython . It's on freenode like #idevgames.

http://pythonmac.org/wiki/MacPythonChannel

They were very helpful when I had questions. It isn't too hard to package up a double-clickable application once you know how.

-Jon
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
Good news and bad news...
With ruby 1.8.1 installed from fink, I got extensions generated with SWIG to work. How would a person go about bundling up that version of ruby and my extensions into an app bundle? Before when I was just using the standard installed version of Ruby, it didn't seem like a problem, but now I don't know what to do.

OSC, that stuff looks great. I'll have to try it out right away.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
My stuff shows how to bundle up Ruby and all the extensions into a stand-alone application.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
Wow, this stuff is really cool. It's somewhat annoying that I have to compile it over SSH (I'm at home) and then fetch it from my computer. So I can't really dig into anything, but this looks very promising.

I don't suppose there is documentation anywhere yet. (or at least well commented?)
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
Skorche Wrote:I don't suppose there is documentation anywhere yet. (or at least well commented?)

LOL LOL

No, anything you want to know, you read the source or you contact me. Pointers to the original ruby extensions my stuff is based off are in the readme file; some of those have documentation.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #10
So let me see if I got some of this right.
1) A program can't get a hold of the window manager if It doesn't have a special piece of code in it. Which is why the SDL and OpenGL extensions I tried before had problems.

2) Embedding the ruby interpreter into a program that has window manager access solves this problem?

3) libruby.a has the entire interpreter in it. (before I thought linking to ruby made it be able to communicate with the ruby interpreter, but not contain it.)

4) If you have a program with an embedded ruby interpreter that creates an opengl context, and the ruby interpreter loads an external bundle, the calls to openGL commands will change the openGL context in the main program. (the dynamically loaded bundles are not treated as a special case.)

This actually seems like it's starting to make sense now. If this stuff is right, then I think I have all my dire questions answered. Thanks a million OSC.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
1&2) only bundled applications can talk to the window manager. GLUT contains a hack to work around this.

Different issue: _objcInit must be called at program startup for Objective C support (required by GLUT, SDL). This is done by the linker under normal circumstances, but if the main program contains no ObjC code, it won't happen. This would also prevent GLUT and SDL extensions from loading into the standard ruby interpreter. It may be possible to work around this (seems like it should be), but I've had no luck.

3) yes, it's the entire interpreter.

4) yes, an OpenGL context is current per-thread, not per-bundle or anything like that.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #12
Yeah, I remember hearing that it needed some objC code or to be bundled or both to get window manager access. I did a quick test last night with a C program that initialized SDL and then opened the ruby interpreter, the interpreter loaded a bundle to open an SDL window... And it all worked!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Ruby on Rails setting Time to NULL BeyondCloister 3 3,963 Nov 21, 2007 09:56 AM
Last Post: AndyKorth
  Ruby, MacPorts, Firewalls BeyondCloister 3 4,142 Nov 6, 2007 04:57 PM
Last Post: OneSadCookie
  Ruby: Resources for Learning iefan 10 6,994 Jul 4, 2007 08:54 AM
Last Post: ALX99066
  Ruby Gems and OpenGL Jaden 2 3,114 Apr 2, 2007 01:15 AM
Last Post: Jaden
  Embedding Ruby DesertPenguin 3 3,493 Jan 5, 2007 09:11 PM
Last Post: DesertPenguin