-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNativeScript.mm
More file actions
87 lines (69 loc) · 2.01 KB
/
NativeScript.mm
File metadata and controls
87 lines (69 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
#include "NativeScript.h"
#include "Runtime.h"
#include "RuntimeConfig.h"
#include "ffi/Tasks.h"
using namespace nativescript;
@implementation Config
@synthesize BaseDir;
@synthesize ApplicationPath;
@synthesize MetadataPtr;
@synthesize IsDebug;
@end
@implementation NativeScript
extern char defaultStartOfMetadataSection __asm("section$start$__DATA$__TNSMetadata");
std::unique_ptr<Runtime> runtime_;
- (void)runScriptString:(NSString*)script runLoop:(BOOL)runLoop {
std::string cppScript = [script UTF8String];
runtime_->RunScript(cppScript);
if (runLoop) {
runtime_->RunLoop();
}
Tasks::Drain();
}
- (void)runMainApplication {
std::string spec = "./app/bundle.js";
runtime_->RunModule(spec);
runtime_->RunLoop();
Tasks::Drain();
}
- (bool)liveSync {
return false;
}
- (void)shutdownRuntime {
runtime_ = nullptr;
}
- (instancetype)initWithConfig:(Config*)config {
if (self = [super init]) {
RuntimeConfig.BaseDir = [config.BaseDir UTF8String];
if (config.ApplicationPath != nil) {
RuntimeConfig.ApplicationPath =
[[config.BaseDir stringByAppendingPathComponent:config.ApplicationPath] UTF8String];
} else {
RuntimeConfig.ApplicationPath =
[[config.BaseDir stringByAppendingPathComponent:@"app"] UTF8String];
}
if (config.MetadataPtr != nil) {
RuntimeConfig.MetadataPtr = [config MetadataPtr];
} else {
RuntimeConfig.MetadataPtr = &defaultStartOfMetadataSection;
}
RuntimeConfig.IsDebug = [config IsDebug];
RuntimeConfig.LogToSystemConsole = [config LogToSystemConsole];
runtime_ = std::make_unique<Runtime>();
// TODO: separate runtime init and measure the time
runtime_->Init();
if (RuntimeConfig.IsDebug) {
// TODO: Inspector for debugging
// runtime_->enableInspector();
}
}
return self;
}
- (instancetype)initializeWithConfig:(Config*)config {
return [self initWithConfig:config];
}
- (void)restartWithConfig:(Config*)config {
[self shutdownRuntime];
[self initWithConfig:config];
}
@end