>Objective C 2.0 blocks could be a good addition to Nu at some point
>though. :)
Well, I managed to implement what I think is a pretty good bridge. I don't know how kosher it is but it works. From nu, I've successfully used Apple's various NSArray, NSDictionary, etc. methods that take blocks and have also had good success with Grand Central Dispatch. I haven't had time to setup a github account as per Tim's advice, but I will do so soon. In the meantime, if any one wants to experiment here are links to the two files that contain the changes:
All of the additions are at the bottom of the two files, it's pretty obvious. Plus some small changes in the nu_calling_objc_method_handler function (look for the #define USE_SIG line and the comment above it). Oh, and now that I think about it, it's missing the necessary preprocessor directives to exclude it on ppc and linux. Probably has some other problems too. I'm in a bit of a rush right now, leaving on a trip tomorrow, but I'll do a more thorough job as soon as I can.
This code definitely falls under the heading, "It was a lot of work, but fortunately someone else did it." Mainly I just did a lot of copying and pasting from the existing functions in bridge.m that handle Objective-C to Nu calls. Like I mentioned above, its a little hackish. I basically just copy a dummy C block and write over it's function pointer with a libffi generated function. But I haven't encountered any problems. The generated blocks seem to copy normally and they work with Grand Central Dispatch.
The basic syntax is
(NuBridgedBlock cBlockWithNuBlock: signature:)
The signature parameter takes a string just like NuBridgedFunction.
Here is a trivial example:
(set nublock (do (arg i stop) (NSLog "arg = #{arg}; index = #{i}")))
(set cblock (NuBridgedBlock cBlockWithNuBlock: nublock signature:"v@I^?"))
(some-ns-array enumerateObjectsUsingBlock:cblock)
I just typed that code in this message, it might not be perfect.
Anyway, I don't know how useful this really is, but it's fun! I'll try to work up some nontrivial example and a write up and post it somewhere.
Let me know what you folks think,
Philip White