From: David <dba...@gm...> - 2006-01-31 17:26:32
|
I had came to this solution as well when testing and it does work. I would have thought though that this could be encapsulated into an RBObject class so that you can hide some of this and do some sanity checks as well? There is a initWithRubyObject in RBObject but would it be useful to have a initWithRubyObjectName? I was also thinking that with XCode it should be possible to write a script that will read your ruby files and generate an objc interface file for them each time you build.. that would be cool.. > Another, possibly simpler, solution is to define an ObjC class in > Ruby: > > class Foo < OSX::NSObject > # ... > def myMethod(arg1) > puts arg1 > end > end > > Then, in objc: > > Class fooClass = NSClassFromString(@"Foo"); > id fooInstance = [[fooClass alloc] init]; > [fooInstance myMethod: @"hello"]; > [the above code is untested - I think the idea is right though] > > > > I imagine there'll be various compiler warnings since there are no > prototypes for the messages being sent to the 'id' variable type. > An objc interface declaration should fix that. > > > > Cheers, > > Jonathan > > |