Skip to content

Instantly share code, notes, and snippets.

@Watson1978
Created December 17, 2011 23:47
Show Gist options
  • Save Watson1978/1491832 to your computer and use it in GitHub Desktop.
Save Watson1978/1491832 to your computer and use it in GitHub Desktop.
Objective-C + MacRuby
#import <Foundation/Foundation.h>
#import <MacRuby/MacRuby.h>
int main(void)
{
id ruby;
id foo;
ruby = [[MacRuby sharedRuntime] evaluateFileAtPath:@"test.rb"];
foo = [ruby performRubySelector:@selector(main:) withArguments:@"from Objc", NULL];
NSLog(@"%@", foo);
NSLog(@"%@", [foo hello]);
}
def main(str)
Foo.new(str)
end
class Foo
def initialize(str = "")
@str = str.to_s
end
def hello
"Hello, MacRuby #{@str}"
end
end
@Watson1978
Copy link
Author

$ gcc objc-macruby.m -framework Foundation -framework MacRuby -fobjc-gc
$ ./a.out                                                              
2011-12-18 08:47:26.728 a.out[43523:60b] #<Foo:0x400cc3000>
2011-12-18 08:47:26.734 a.out[43523:60b] Hello, MacRuby from Objc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment