|
From: Rod S. <rsc...@xm...> - 2004-01-02 00:35:30
|
At Mon, 13 Oct 2003 10:13:09 -0600,
Rod Schmidt wrote:
> Unless I'm missing something (you may need to point me to something
more
> specific), I think you misunderstood me. I'm not trying to call Cocoa
> classes from Ruby but Ruby classes from an Objective-C Cocoa app.
I'm very sorry. You was not missing anything, but I had jumped to
a misleading conclusion about your message. Now, I have understood
your question, maybe.
I was wondering how the below would work with your own class and with
calling methods with arguments. For example I have a class called
Engine written in Ruby with a constructor that takes a file name. How
do I get the class to pass to initWithRubyObject and how do I pass
arguments to a method. Is it as simple as [class new: filename] or
[[class alloc] init: filename]; Basically how do ruby's allocation
scheme translate when you're trying to use it as an objective-c class.
Rod
> Is there another way to do this besides using Ruby's C API.? How
> could I do it using the RubyCocoa framework?
I guess that the following show an answer of your question:
/* cc -I/usr/lib/ruby/1.6/powerpc-darwin6.0 -framework Cocoa
-framework RubyCocoa test.m */
#import <Cocoa/Cocoa.h>
#import <RubyCocoa/RubyCocoa.h>
int main()
{
id pool;
id obj;
RBRubyCocoaInit(); /* initialize Ruby and RubyCocoa */
pool = [[NSAutoreleasePool alloc] init];
obj = [RBObject RBObjectWithRubyScriptCString: "'hello world'" ]; /*
eval string */
NSLog(@"%@", obj);
obj = [[RBObject alloc] initWithRubyObject: rb_cTime];
NSLog(@"%@", obj);
obj = [obj now]; /* obj is a RBObject with wrapping a result of
obj.now */
NSLog(@"%@", obj);
[pool release];
return 0;
}
--
Hisa
|