Skip to content

Instantly share code, notes, and snippets.

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

kyab commented Dec 18, 2011

$ gcc objc-macruby.m -framework Foundation -framework MacRuby -fobjc-gc
$ ./a.out
2011-12-18 18:04:10.356 a.out[27436:60b] #Foo:0x400cb8e40
2011-12-18 18:04:10.365 a.out[27436:60b] Hello, MacRuby from Objc

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