Skip to content

Instantly share code, notes, and snippets.

@Kureev

Kureev/ChakraProxy+run.m

Last active Oct 17, 2016
Embed
What would you like to do?
@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