Skip to content

Instantly share code, notes, and snippets.

@Kureev
Last active October 17, 2016 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kureev/24c173b74f7caaf9cebc22daa2d11859 to your computer and use it in GitHub Desktop.
Save Kureev/24c173b74f7caaf9cebc22daa2d11859 to your computer and use it in GitHub Desktop.
@implementation ChakraProxy
-(void)run {
unsigned currentSourceContext = 0;
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"js"];
NSError *error;
NSString *fileContents = [NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:&error];
if (error) {
NSLog(@"Error reading file: %@", error.localizedDescription);
}
const char *script = [fileContents cStringUsingEncoding:NSASCIIStringEncoding];
// Create a runtime
JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime);
// Create a context
JsCreateContext(runtime, &context);
JsSetCurrentContext(context);
// Run script
JsRunScriptUtf8(script, currentSourceContext++, "", nullptr);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment