Class: Motion::Project::OSXConfig

Inherits:
XcodeConfig
  • Object
show all
Defined in:
lib/project/motion-osx-cli.rb

Instance Method Summary collapse

Instance Method Details

#main_cpp_file_txt(spec_objs) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/project/motion-osx-cli.rb', line 28

def main_cpp_file_txt(spec_objs)
  main_txt = ""
  if frameworks.include?('AppKit')
    main_txt << "#import <AppKit/AppKit.h>"
  else
    main_txt << "#import <Foundation/Foundation.h>"
  end
  main_txt << <<EOS


extern "C" {
void rb_define_global_const(const char *, void *);
void rb_rb2oc_exc_handler(void);
void rb_exit(int);
void RubyMotionInit(int argc, char **argv);
EOS
  if spec_mode
    spec_objs.each do |_, init_func|
      main_txt << "void #{init_func}(void *, void *);\n"
    end
  end
  main_txt << <<EOS
}
EOS
  if spec_mode
    main_txt << <<EOS
@interface SpecLauncher : NSObject
@end

@implementation SpecLauncher

- (void)runSpecs
{
EOS
    spec_objs.each do |_, init_func|
      main_txt << "#{init_func}(self, 0);\n"
    end
    main_txt << <<EOS
    [NSClassFromString(@\"Bacon\") performSelector:@selector(run)];
}

- (void)appLaunched:(NSNotification *)notification
{
[self runSpecs];
}

@end
EOS
  end

  main_txt << <<EOS
int
main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
EOS
if ENV['ARR_CYCLES_DISABLE']
  main_txt << <<EOS
setenv("ARR_CYCLES_DISABLE", "1", true);
EOS
end
main_txt << <<EOS
RubyMotionInit(argc, argv);
EOS
if spec_mode && frameworks.include?('AppKit')
  main_txt << "SpecLauncher *specLauncher = [[SpecLauncher alloc] init];\n"
  main_txt << "[[NSNotificationCenter defaultCenter] addObserver:specLauncher selector:@selector(appLaunched:) name:NSApplicationDidFinishLaunchingNotification object:nil];\n"
end
main_txt << <<EOS
NSMutableArray * arguments = [[NSMutableArray alloc] initWithCapacity: argc];
for (int i = 0; i < argc; i++)
{
    [arguments addObject: [NSString stringWithUTF8String: argv[i]]];
}
[[NSClassFromString(@"#{delegate_class}") new] performSelector:NSSelectorFromString(@"main:") withObject:[NSNumber numberWithInt:argc] withObject:arguments];
[pool release];
rb_exit(0);
return 0;
}
EOS
end