Skip to content

Instantly share code, notes, and snippets.



Last active Oct 17, 2016
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);
// Run script
JsRunScriptUtf8(script, currentSourceContext++, "", nullptr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment