Permalink
Browse files

Added a signature operator to allow nu code an easy way to convert sy…

…mbols to ObjC type signatures.

Updated the cblock macro in cblocks.nu to use the signature operator.
Added a test for c blocks to the TestBridge class.
  • Loading branch information...
1 parent 975bb7e commit 217c2eaf1a1c198c7cf12b1c359ce9ccb4970076 @philipwhite philipwhite committed Oct 16, 2011
Showing with 20 additions and 8 deletions.
  1. +2 −5 nu/cblocks.nu
  2. +15 −0 objc/Nu.m
  3. +3 −3 test/test_bridge.nu
View
@@ -28,10 +28,7 @@
(try ((NuBridgedBlock class))
(catch (execption) (throw* "NuException" "This build of Nu does not support C blocks.")))
- (function __get_type_signature (identifier)
- (((NuBridgedFunction functionWithName:"signature_for_identifier" signature:"@@@") identifier
- (NuSymbolTable sharedSymbolTable))))
- (set __sig (__get_type_signature (list ret)))
+ (set __sig (signature (list ret)))
(set __blockparams ())
(set __paramlist params)
(until (eq __paramlist nil)
@@ -42,7 +39,7 @@
(set __param (car (cdr __paramlist)))
(set __paramlist (cdr (cdr __paramlist)))
(set __sig (__sig stringByAppendingString:
- (__get_type_signature __type)))
+ (signature __type)))
(set __blockparams (append __blockparams (list __param))))
;(puts "Signature: #{__sig}")
;(puts "Block params: #{__blockparams}")
View
@@ -8925,6 +8925,19 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
@end
+@interface Nu_signature_operator : NuOperator {}
+@end
+
+@implementation Nu_signature_operator
+
+// signature operator; basically gives access to the static signature_for_identifier function from within Nu code
+- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
+{
+ return signature_for_identifier( [[cdr car] evalWithContext:context],[NuSymbolTable sharedSymbolTable]);
+}
+
+@end
+
#define install(name, class) [(NuSymbol *) [symbolTable symbolWithString:name] setValue:[[[class alloc] init] autorelease]]
void load_builtins(NuSymbolTable *symbolTable);
@@ -9057,6 +9070,8 @@ void load_builtins(NuSymbolTable *symbolTable)
install(@"?", Nu_help_operator);
install(@"version", Nu_version_operator);
+ install(@"signature", Nu_signature_operator);
+
// set some commonly-used globals
[(NuSymbol *) [symbolTable symbolWithString:@"NSUTF8StringEncoding"]
setValue:[NSNumber numberWithInt:NSUTF8StringEncoding]];
View
@@ -39,8 +39,8 @@
(num-array (array 1 2)))
(set equals-num? (cblock BOOL ((id) obj (unsigned long) idx (void*) stop)
(if (== obj num) YES (else NO))))
+ (set num 1)
+ (assert_equal 0 (num-array indexOfObjectPassingTest:equals-num?))
(set num 2)
- (assert_equal 1 (num-array indexOfObjectPassingTest:equals-num?))
- (set num 3)
- (assert_equal NSNotFound (num-array indexOfObjectPassingTest:equals-num?)))))
+ (assert_equal 1 (num-array indexOfObjectPassingTest:equals-num?)))))

0 comments on commit 217c2ea

Please sign in to comment.