------------
var f = function(err) {
print("Hello from a jsfunction");
};
var objcBlock = JSTestBlocks.newErrorBlockForJSFunction_(f);
print(objcBlock);
JSTestBlocks.testFunction_(objcBlock);
------------
Where newErrorBlockForJSFunction just returns an objc block that calls the js function:
------------
@interface JSTestBlocks : NSObject { } @end
@implementation JSTestBlocks
+ (id)newErrorBlockForJSFunction:(JSValueRefAndContextRef)callbackFunction {
void (^theBlock)(NSError *) = ^(NSError *err) {
id jsc = [JSCocoa controllerFromContext:callbackFunction.ctx];
[jsc callJSFunction:callbackFunction.value withArguments:[NSArray arrayWithObjects:err, nil]];
};
return [theBlock copy];
}
+ (void)testFunction:(void (^)(NSError *))theBlock {
theBlock(nil);
}
@end
------------
JSCocoa ends up complaining about having -3 arguments, when 1 is required. Any idea what needs to be changed to allow this? Is it the type encodings? Something else?
thanks,
-gus
--
August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/
--
JSCocoa: http://inexdo.com/JSCocoa
Source: http://github.com/parmanoir/jscocoa/tree/master
Docs: http://code.google.com/p/jscocoa/
Group: http://groups.google.com/group/jscocoa
Unsubscribe: jscocoa+u...@googlegroups.com
> Fixed. Blocks are encoded as '@?', JSCocoa did not support those.
Awesome- thanks! Verified that it works too!
> Regarding the callbackFunction : the context you get is not the main
> context, but more like a call stack, therefore it will be invalid once
> control returns from your block creation.
<snip>
Thanks for clarifying that as well. Tried it out, and it works. This will be great for some tests I use.