Permalink
Browse files

Ruby interface is starting to work with MacRuby.

  • Loading branch information...
1 parent bc9fe5b commit 62fed03432a0e05e6ffcd89c04339458c3496134 @Grayson committed Mar 4, 2009
Showing with 19 additions and 34 deletions.
  1. +1 −16 src/RubyPluginManager.h
  2. +18 −18 src/RubyPluginManager.m
View
@@ -7,13 +7,12 @@
//
#import <Cocoa/Cocoa.h>
-#import <RubyCocoa/RBRuntime.h>
+#import <MacRuby/MacRuby.h>
#import "PluginManager.h"
#import "PluginManagerProtocol.h"
@interface RubyPluginManager : NSObject <PluginManagerProtocol> {
NSMutableDictionary *_plugins;
- Class RBObject;
}
@property (retain) NSMutableDictionary *plugins;
@@ -25,17 +24,3 @@
-(id)runScriptAtPath:(NSString *)path;
@end
-
-// RBObject isn't provided by RBRuntime.h so it's loaded dynamically. This prevents linker warnings when
-// loading the RBObject.
-@interface NSObject (RBObject)
--(id) RBObjectWithRubyScriptString:(NSString *)script;
-@end
-
-// A simple interface to avoid linker warnings when calling into the RBObject.
-@interface NSObject(RubyPlugin)
--actionProperty;
--actionEnable:withValue :forValue;
--actionTitle:withValue :forValue;
--actionPerform:withValue :forValue;
-@end
View
@@ -18,7 +18,7 @@ @implementation RubyPluginManager
+(void)load {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
- if (NSClassFromString(@"RBObject")) [PluginManager registerManager:[[self new] autorelease]];
+ if (NSClassFromString(@"MacRuby")) [PluginManager registerManager:[[self new] autorelease]];
[pool release];
}
@@ -27,13 +27,6 @@ -(id)init
self = [super init];
if (!self) return nil;
- // Simple initialization of the Ruby runtime and loading of RubyCocoa.
- // Also RBObject is available in RubyCocoa but isn't made public. It is loaded dynamically here.
- ruby_init();
- ruby_init_loadpath();
- RBRubyCocoaInit();
- RBObject = NSClassFromString(@"RBObject");
-
return self;
}
@@ -46,18 +39,25 @@ -(void)build
{
// Could it be any easier to load a Ruby script with RubyCocoa? Simply get a script as an NSString
// and load it using RBObjectWithRubyScriptString:.
+ MacRuby *ruby = [MacRuby sharedRuntime];
+ // id x = [ruby evaluateFileAtPath:scriptPath];
+ // NSLog(@"%s %@", _cmd, x);
+ VALUE script = rb_eval_string([[NSString stringWithContentsOfFile:scriptPath] UTF8String]);
+ NSLog(@"%s WTF IS GOING ON?", _cmd);
+
+ VALUE ret = rb_funcall(script, rb_intern("actionPerform"), 2, OC2RB(self), OC2RB(@"asdf"));
+ NSLog(@"%s %@", _cmd, RB2OC(ret));
- id rb = [RBObject RBObjectWithRubyScriptString:[NSString stringWithContentsOfFile:scriptPath]];
- if (!rb) continue;
+ return;
- // RBObjects are really NSProxies. RubyCocoa makes it easy to call functions in a Ruby script
- // simply by calling the function name as a proxy method. Here, it'll be calling `actionProperty()`
- // from the loaded script.
- NSString *property = [rb actionProperty];
- NSMutableArray *arr = [plugins objectForKey:property];
- if (!arr) arr = [NSMutableArray array];
- [arr addObject:rb];
- [plugins setObject:arr forKey:property];
+ // // RBObjects are really NSProxies. RubyCocoa makes it easy to call functions in a Ruby script
+ // // simply by calling the function name as a proxy method. Here, it'll be calling `actionProperty()`
+ // // from the loaded script.
+ // NSString *property = [rb actionProperty];
+ // NSMutableArray *arr = [plugins objectForKey:property];
+ // if (!arr) arr = [NSMutableArray array];
+ // [arr addObject:rb];
+ // [plugins setObject:arr forKey:property];
}
}

0 comments on commit 62fed03

Please sign in to comment.