@@ -21,18 +21,63 @@ @implementation Config
2121
2222@implementation NativeScript
2323
24- std::unique_ptr<Runtime> runtime_ ;
24+ extern char defaultStartOfMetadataSection __asm ( " section$start$__DATA$__TNSMetadata " ) ;
2525
26- - (instancetype )initWithConfig : (Config*)config {
26+ - (void )runScriptString : (NSString *) script runLoop : (BOOL ) runLoop {
27+
28+ std::string cppString = std::string ([script UTF8String ]);
29+ runtime_->RunScript (cppString);
2730
31+ if (runLoop) {
32+ CFRunLoopRunInMode (kCFRunLoopDefaultMode , 0 , true );
33+ }
34+
35+
36+ tns::Tasks::Drain ();
37+
38+ }
39+
40+ std::unique_ptr<Runtime> runtime_;
41+
42+ - (void )runMainApplication {
43+ runtime_->RunMainScript ();
44+
45+ CFRunLoopRunInMode (kCFRunLoopDefaultMode , 0 , true );
46+ tns::Tasks::Drain ();
47+ }
48+
49+ - (bool )liveSync {
50+ if (runtime_ == nullptr ) {
51+ return false ;
52+ }
53+
54+ Isolate* isolate = runtime_->GetIsolate ();
55+ return tns::LiveSync (isolate);
56+ }
57+
58+ - (void )shutdownRuntime {
59+ if (RuntimeConfig.IsDebug ) {
60+ Console::DetachInspectorClient ();
61+ }
62+ tns::Tasks::ClearTasks ();
63+ if (runtime_ != nullptr ) {
64+ runtime_ = nullptr ;
65+ }
66+ }
67+
68+ - (instancetype )initializeWithConfig : (Config*)config {
2869 if (self = [super init ]) {
2970 RuntimeConfig.BaseDir = [config.BaseDir UTF8String ];
3071 if (config.ApplicationPath != nil ) {
3172 RuntimeConfig.ApplicationPath = [[config.BaseDir stringByAppendingPathComponent: config.ApplicationPath] UTF8String ];
3273 } else {
3374 RuntimeConfig.ApplicationPath = [[config.BaseDir stringByAppendingPathComponent: @" app" ] UTF8String ];
3475 }
35- RuntimeConfig.MetadataPtr = [config MetadataPtr ];
76+ if (config.MetadataPtr != nil ) {
77+ RuntimeConfig.MetadataPtr = [config MetadataPtr ];
78+ } else {
79+ RuntimeConfig.MetadataPtr = &defaultStartOfMetadataSection;
80+ }
3681 RuntimeConfig.IsDebug = [config IsDebug ];
3782 RuntimeConfig.LogToSystemConsole = [config LogToSystemConsole ];
3883
@@ -58,26 +103,19 @@ - (instancetype)initWithConfig:(Config*)config {
58103 Console::AttachInspectorClient (inspectorClient);
59104 }
60105 }
61-
62106 return self;
63107
64108}
65109
66- - (void )runMainApplication {
67- runtime_->RunMainScript ();
68-
69- CFRunLoopRunInMode (kCFRunLoopDefaultMode , 0 , true );
110+ - (instancetype )initWithConfig : (Config*)config {
111+ return [self initializeWithConfig: config];
112+ }
70113
71- tns::Tasks::Drain ();
114+ - (void )restartWithConfig : (Config*)config {
115+ [self shutdownRuntime ];
116+ [self initializeWithConfig: config];
72117}
73118
74- - (bool )liveSync {
75- if (runtime_ == nullptr ) {
76- return false ;
77- }
78119
79- Isolate* isolate = runtime_->GetIsolate ();
80- return tns::LiveSync (isolate);
81- }
82120
83121@end
0 commit comments