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 << "\n\nextern \"C\" {\nvoid rb_define_global_const(const char *, void *);\nvoid rb_rb2oc_exc_handler(void);\nvoid rb_exit(int);\nvoid RubyMotionInit(int argc, char **argv);\n"
  if spec_mode
    spec_objs.each do |_, init_func|
      main_txt << "void #{init_func}(void *, void *);\n"
    end
  end
  main_txt << "}\n"
  if spec_mode
    main_txt << "@interface SpecLauncher : NSObject\n@end\n\n@implementation SpecLauncher\n\n- (void)runSpecs\n{\n"
    spec_objs.each do |_, init_func|
      main_txt << "#{init_func}(self, 0);\n"
    end
    main_txt << "    [NSClassFromString(@\\\"Bacon\\\") performSelector:@selector(run)];\n}\n\n- (void)appLaunched:(NSNotification *)notification\n{\n[self runSpecs];\n}\n\n@end\n"
  end

  main_txt << "int\nmain(int argc, char **argv)\n{\nNSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\n"
if ENV['ARR_CYCLES_DISABLE']
  main_txt << "setenv(\"ARR_CYCLES_DISABLE\", \"1\", true);\n"
end
main_txt << "RubyMotionInit(argc, argv);\n"
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 << "NSMutableArray * arguments = [[NSMutableArray alloc] initWithCapacity: argc];\nfor (int i = 0; i < argc; i++)\n{\n    [arguments addObject: [NSString stringWithUTF8String: argv[i]]];\n}\n[[NSClassFromString(@\"\#{delegate_class}\") new] performSelector:NSSelectorFromString(@\"main:\") withObject:[NSNumber numberWithInt:argc] withObject:arguments];\n[pool release];\nrb_exit(0);\nreturn 0;\n}\n"
end