EvalJS 0.0.4

EvalJS 0.0.4

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.



EvalJS 0.0.4

  • By
  • Francis Chong

EvalJS lets you run JavaScript code from your iOS app. It is based on JavaScriptCore and Ejecta, but does not contain any DOM or Canvas/Audio objects.

Status

Experimental. This has not been used in production yet and should be considered as a proof of concept.

Usage

Evaulate Javascript

EvalJS* js = [[EvalJS alloc] init];
[js eval:@"function test(a, b) {return a + b; }"];

id result = [js eval:@"test(3, 2)"];
NSLog(@"result: %@", result);

Create Javascript function that invoke Objective-C block

EvalJS* js = [[EvalJS alloc] init];
[js createFunction:@"hello" callback:^id(NSUInteger argc, NSArray *argv) {
    NSLog(@"hello: %@", [argv objectAtIndex:0]);
    return @"world";
}];

NSString* result = [js eval:@"hello(3)"];

The output would be:

hello: 3

License

Copyright (c) 2013 Francis Chong [email protected].

Released under the MIT license. See LICENSE for details.