-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow embedding into Swift host projects #231
Changes from 4 commits
3ca9cb1
deabadf
41d55f5
772c613
b1350e7
1b18e9c
f44aa18
b93e99c
0a15501
6055045
ef27957
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,18 +21,68 @@ @implementation Config | |
|
||
@implementation NativeScript | ||
|
||
std::unique_ptr<Runtime> runtime_; | ||
extern char defaultStartOfMetadataSection __asm("section$start$__DATA$__TNSMetadata"); | ||
|
||
- (instancetype)initWithConfig:(Config*)config { | ||
- (void)runScriptString: (NSString*) script runLoop: (BOOL) runLoop { | ||
|
||
std::string cppString = std::string([script UTF8String]); | ||
runtime_->RunScript(cppString); | ||
|
||
if (runLoop) { | ||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); | ||
} | ||
|
||
|
||
tns::Tasks::Drain(); | ||
|
||
} | ||
|
||
std::unique_ptr<Runtime> runtime_; | ||
|
||
- (void)runMainApplication { | ||
runtime_->RunMainScript(); | ||
|
||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); | ||
|
||
tns::Tasks::Drain(); | ||
} | ||
|
||
- (bool)liveSync { | ||
if (runtime_ == nullptr) { | ||
return false; | ||
} | ||
|
||
Isolate* isolate = runtime_->GetIsolate(); | ||
return tns::LiveSync(isolate); | ||
} | ||
|
||
- (void)shutdownRuntime { | ||
if (runtime_ != nullptr) { | ||
Isolate* isolate = runtime_->GetIsolate(); | ||
{ | ||
v8::Locker l(isolate); | ||
v8::Isolate::Scope isolate_scope(isolate); | ||
v8::HandleScope handle_scope(isolate); | ||
|
||
isolate->Dispose(); | ||
} | ||
runtime_ = nullptr; | ||
} | ||
} | ||
|
||
- (void)initializeWithConfig:(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]; | ||
} | ||
RuntimeConfig.MetadataPtr = [config MetadataPtr]; | ||
if (config.MetadataPtr != nil) { | ||
RuntimeConfig.MetadataPtr = [config MetadataPtr]; | ||
} else { | ||
RuntimeConfig.MetadataPtr = &defaultStartOfMetadataSection; | ||
} | ||
RuntimeConfig.IsDebug = [config IsDebug]; | ||
RuntimeConfig.LogToSystemConsole = [config LogToSystemConsole]; | ||
|
||
|
@@ -59,25 +109,20 @@ - (instancetype)initWithConfig:(Config*)config { | |
} | ||
} | ||
|
||
return self; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this still return self? |
||
|
||
} | ||
|
||
- (void)runMainApplication { | ||
runtime_->RunMainScript(); | ||
|
||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); | ||
- (instancetype)initWithConfig:(Config*)config { | ||
if (self = [super init]) { | ||
[self initializeWithConfig:config]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. init will be called twice if this method is called (one here and another in initializeWithConfig) |
||
return self; | ||
} | ||
|
||
tns::Tasks::Drain(); | ||
- (void)restartWithConfig:(Config*)config { | ||
[self shutdownRuntime]; | ||
[self initializeWithConfig:config]; | ||
} | ||
|
||
- (bool)liveSync { | ||
if (runtime_ == nullptr) { | ||
return false; | ||
} | ||
|
||
Isolate* isolate = runtime_->GetIsolate(); | ||
return tns::LiveSync(isolate); | ||
} | ||
|
||
@end |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do we generate this again when the metadata is updated? Shouldn't this just be part of the build process? |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all these changes necessary in this pbxproj file @tdermendjiev ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this likely shouldn't be done here (the runtime destructor is responsible for deleting this isolate)