I'm using JavaScriptCore to evaluate some simple scripts in my app. I'm creating a global object and defining some properties on it like so:
JSContext *context = [[JSContext alloc] init];
JSValue *globalObject = [context globalObject];
[globalObject setValue:fields forProperty:@"fields"];
...
So then the script can access the values in fields and so on. I'd like scripts to be able to use a function called lookup, and I already have an Objective-C implementation for this function.
How do I add a property to the global object which is a function that calls back to my Objective-C method? I see that there's a function called JSObjectMakeFunctionWithCallback, but that uses the low-level C constructs like JSObjectRefs and takes a C function, not an Objective-C block, so I can't make use of self inside the implementation.