Skip to content
Newer
Older
100644 132 lines (112 sloc) 2.77 KB
4b7c757 cleaning a bit public headers, added support for methods defined for …
Laurent Sansonetti authored
1 /*
2 * MacRuby Objective-C API.
7d7d3e8 @ferrous26 Change ownership to The MacRuby Team and update copyrights
ferrous26 authored
3 *
4b7c757 cleaning a bit public headers, added support for methods defined for …
Laurent Sansonetti authored
4 * This file is covered by the Ruby license. See COPYING for more details.
5 *
7d7d3e8 @ferrous26 Change ownership to The MacRuby Team and update copyrights
ferrous26 authored
6 * Copyright (C) 2012, The MacRuby Team. All rights reserved.
9595725 update copyrights to 2011
Laurent Sansonetti authored
7 * Copyright (C) 2009-2011, Apple Inc. All rights reserved.
4b7c757 cleaning a bit public headers, added support for methods defined for …
Laurent Sansonetti authored
8 */
9
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
10 #import <Foundation/Foundation.h>
4b7c757 cleaning a bit public headers, added support for methods defined for …
Laurent Sansonetti authored
11
d0898dd include/ruby/macruby.h -> macruby_internal.h
Laurent Sansonetti authored
12 #include "macruby_internal.h"
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
13 #include "ruby/node.h"
14 #include "ruby/objc.h"
cb65416 the great schism, part I
Laurent Sansonetti authored
15 #include "vm.h"
4b7c757 cleaning a bit public headers, added support for methods defined for …
Laurent Sansonetti authored
16 #include "objc.h"
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
17
18 @implementation MacRuby
19
21174f3 remove historical dlog variables + misc cleanup
Laurent Sansonetti authored
20 extern bool ruby_initialized;
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
21
22 + (MacRuby *)sharedRuntime
23 {
24 static MacRuby *runtime = nil;
25 if (runtime == nil) {
26 runtime = [[MacRuby alloc] init];
21174f3 remove historical dlog variables + misc cleanup
Laurent Sansonetti authored
27 if (!ruby_initialized) {
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
28 int argc = 0;
29 char **argv = NULL;
30 ruby_sysinit(&argc, &argv);
31 ruby_init();
7ffb044 +[MacRuby sharedRuntime]: initialize the load path
Laurent Sansonetti authored
32 ruby_init_loadpath();
d1c82a3 forgot to initialize the compiler
Laurent Sansonetti authored
33 rb_vm_init_compiler();
1f78b11 +[MacRuby sharedRuntime]: don't forget to init the jit
Laurent Sansonetti authored
34 rb_vm_init_jit();
efb0a3f +[MacRuby sharedRuntime]: make the load path relocatable in case MacR…
Laurent Sansonetti authored
35 rb_objc_fix_relocatable_load_path();
a3a0414 Xcode MacRuby apps will load the BridgeSupport files of frameworks li…
Laurent Sansonetti authored
36 rb_objc_load_loaded_frameworks_bridgesupport();
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
37 }
38 }
39 return runtime;
40 }
41
42 - (id)evaluateString:(NSString *)expression
43 {
44 return RB2OC(rb_eval_string([(NSString *)expression UTF8String]));
45 }
46
47 - (id)evaluateFileAtPath:(NSString *)path
48 {
7929572 fix -[MacRuby evaluateFileAtPath:] to behave like #require, so that i…
Laurent Sansonetti authored
49 return RB2OC(rb_f_require(Qnil, (VALUE)path));
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
50 }
51
52 - (id)evaluateFileAtURL:(NSURL *)URL
53 {
54 if (![URL isFileURL]) {
55 [NSException raise:NSInvalidArgumentException format:
56 @"given URL is not a file URL"];
57 }
58 return [self evaluateFileAtPath:[URL relativePath]];
59 }
60
61 - (void)loadBridgeSupportFileAtPath:(NSString *)path
62 {
a6a5d3e started to trim out the static library
Laurent Sansonetti authored
63 #if MACRUBY_STATIC
64 printf("loadBridgeSupportFileAtPath: not supported in MacRuby static\n");
65 abort();
66 #else
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
67 rb_vm_load_bridge_support([path fileSystemRepresentation], NULL, 0);
a6a5d3e started to trim out the static library
Laurent Sansonetti authored
68 #endif
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
69 }
70
71 - (void)loadBridgeSupportFileAtURL:(NSURL *)URL
72 {
73 if (![URL isFileURL]) {
74 [NSException raise:NSInvalidArgumentException format:
75 @"given URL is not a file URL"];
76 }
77 [self loadBridgeSupportFileAtPath:[URL relativePath]];
78 }
79
80 @end
81
82 @implementation NSObject (MacRubyAdditions)
83
84 - (id)performRubySelector:(SEL)sel
85 {
86 return [self performRubySelector:sel withArguments:NULL];
87 }
88
89 - (id)performRubySelector:(SEL)sel withArguments:(id *)argv count:(int)argc
90 {
91 VALUE *rargv = NULL;
92 if (argc > 0) {
370e385 get rid of bad allocas, disable frame pointer elimination, simplified…
Laurent Sansonetti authored
93 rargv = (VALUE *)xmalloc(sizeof(VALUE) * argc);
94 for (int i = 0; i < argc; i++) {
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
95 rargv[i] = OC2RB(argv[i]);
96 }
97 }
98
70ea0b5 per-vm method cache + misc fixes/improvements
Laurent Sansonetti authored
99 return RB2OC(rb_vm_call(OC2RB(self), sel, argc, rargv));
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
100 }
101
102 - (id)performRubySelector:(SEL)sel withArguments:firstArg, ...
103 {
104 va_list args;
105 int argc;
106 id *argv;
107
108 if (firstArg != nil) {
109 argc = 1;
110 va_start(args, firstArg);
af0b99c misc change
Laurent Sansonetti authored
111 while (va_arg(args, id) != NULL) {
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
112 argc++;
113 }
114 va_end(args);
370e385 get rid of bad allocas, disable frame pointer elimination, simplified…
Laurent Sansonetti authored
115 argv = xmalloc(sizeof(id) * argc);
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
116 va_start(args, firstArg);
117 argv[0] = firstArg;
370e385 get rid of bad allocas, disable frame pointer elimination, simplified…
Laurent Sansonetti authored
118 for (int i = 1; i < argc; i++) {
07580b1 moved the MacRuby ObjC API into a separate file
Laurent Sansonetti authored
119 argv[i] = va_arg(args, id);
120 }
121 va_end(args);
122 }
123 else {
124 argc = 0;
125 argv = NULL;
126 }
127
128 return [self performRubySelector:sel withArguments:argv count:argc];
129 }
130
131 @end
Something went wrong with that request. Please try again.