Type Reference

Here are some notes on the handling of special types in Nu.

Numbers

Numbers in Nu are always represented by NSNumber instances. Objective-C methods and functions that return numeric values will return NSNumber objects to their callers when they are called from Nu. Method and function arguments that expect numeric values should be passed NSNumber objects from Nu, but this is handled automatically by Nu.

Strings

Strings in Nu are always represented by NSString instances. Objective-C methods and functions that return C strings will return NSString objects to their callers when they are called from Nu. Method and function arguments that expect C strings should be passed NSString objects from Nu, but this should not be a concern because it is handled automatically by Nu. Do not expect to pass mutable strings this way. Functions that expect mutable strings should only be called from Objective-C.

Selectors

Method selectors are not objects in Objective-C. They are instances of an opaque type called SEL, and in Nu code they are represented by their names, represented as strings. Objective-C methods and functions that return selectors will return strings when they are called from Nu. Method and function arguments that expect selectors should be passed strings from Nu that correspond to the selector names.

Here's an example that sets a button action with Nu:

(button setAction:"seed:")

Special Structures

The Cocoa structures NSRect, NSPoint, NSSize, and NSRange are all represented as lists in Nu. Methods and functions that return these types will return lists to their Nu callers. Method and function arguments that expect these types should be passed Nu lists.

Here's an example that passes an NSRect to a view's initWithFrame: method:

 (view initWithFrame:'(0 0 100 100))

The ordering of elements within the lists follows Cocoa conventions. For each type, the ordering is as follows:

NSRectx origin, y origin, width, height
NSPointx, y
NSSizewidth, height
NSRangestart, length

Type Signatures

The Objective-C runtime uses a special encoding to represent type signatures for methods, functions, and variables.

Here is a definitive list of type codes on Apple's Developer Connection site.