From: John Joyce Date: 2007-10-01T11:08:36+09:00 Subject: Re: Help with a Windows port of a Ruby extension On Sep 30, 2007, at 2:56 PM, Scott Mckie wrote: > I'm working on a game that's in the early stages, and I want to make > sure it runs on both OS X and Windows before I continue > development. OS > X is my primary OS, and it runs fine on that. But it crashes in > Windows. > > The setup is this: the core of the game is written in Objective C, > and > I'm using Ruby for the scripting of the game. I wrote a very small > Ruby > extension to act as a bridge between the two (basically a wrapper > around > the Objective C game objects). Everything was fine, in OS X. In > order > to get it to compile in Windows, I had to write a separate > extension to > act as a wrapper around the Objective C /classes/ and do a hairy > little > dance to register them, because I don't of a compiler flag in the > standard gcc that's an equivalent of Apple's -undefined suppress, > and I > don't want to link against all the main project files in the > extension. > > And so, my current problem: it still runs fine in OS X, but it chokes > when I try to create the Objective C object from within the Ruby > extension. I create the Ruby class-wrapper object, register the > Objective C class, test it thoroughly to make sure that it's > behaving as > expected -- it's all fine when I do it from the main program. I even > tried printing the pointer to the Obj-C class to make sure it's not > getting mangled, and it doesn't seem to change at all. But all I > get is > garbage when I try to instantiate the class. > > I realize that my problem might likely turn out to have nothing to do > with Ruby itself. In truth, the Ruby part seems to be behaving as > expected. I pose the question here because I think I'm likely to find > more Ruby people with experience in Objective C than Objective C > people > with experience in Ruby. And likewise for Windows. > > I'm using Ruby 1.8.6 on both machines. My Mac is running OS 10.4.10, > and the Windows machine I'm using for development is ... Windows XP > Home. I'll put the source up at > http://greay.phpwebhosting.com/shooter/shooter.r67.zip for people to > look at, as well. > -- > Posted via http://www.ruby-forum.com/. > Well, if you want Objective-C to be portable, you'll have to build it with GNUStep/OpenStep instead of Cocoa. This can be difficult since many functions and libraries in Cocoa are not found in the GNU stuff. For the most part you can consider Objective-C to be OS X only, just as much of what is written for Windows uses Windows-only code that can't be ported, or ported easily. Regardless, Windows doesn't include the necessary runtime for Objective-C. You might want to re-write using another language instead of Obj-C to make it crossplatform.