Joy Online Manual

NAME
Objective-C message expression

SYNOPSIS

[expr selector|{keyword-argument-list[, argument-list]}]

[super selector|{keyword-argument-list[, argument-list]}]

[former selector|{keyword-argument-list[, argument-list]}]

object.selector()

object["selector:selector:..."](arg1, arg2, ...)

DESCRIPTION
Joy allows you to send messages to Objective-C objects and classes in either Objective-C or JavaScript syntax.  When the message selector contains colons, the Objective-C syntax is much more readable, though. Because JavaScript tokenizes your code, you don't have to insert spaces between keyword selectors and arguments as in Tcl.

The super message target works like the Objective-C construct of the same name; note that when you message super from a method defined for a single instance, Joy will start looking for an implementation at the level of the instance's class, not the superclass.

The special message target former tells Joy to use the implementation of the selector that was in effect just before the currently executing JavaScript implementation was added (that includes superclass implementations).

If no super or former implementation is found, the call will just return self.

You can send messages with a variable number of arguments, but only if the variable arguments are all of the same type as the last fixed argument. (Joy will not generally understand printf-like API's, unless the arguments happen to be all char * or all id).

Messages to nil are legal, like in Objective-C; they return nil.

Forwarding of messages works as in Objective-C. You can even implement the methodSignatureForSelector: and forwardInvocation: methods in JavaScript.

EXAMPLES

js> pi = [[NSNumber numberWithDouble: M_PI] retain]
(NSdoubleNumber *)0x1f1494
js> [pi description]
3.1415926535897931
js> [[NSArray arrayWithObjects:"pi", pi/2, pi, nil] description]
(pi, 1.5707963267948966, 3.1415926535897931)
js> NSDecimalNumber.one().description()
1
js> @teach NSObject test { return "test1" } @end
js> @teach NSObject test { return [former test] + " test2" } @end
js> o = [[NSObject alloc] init]
(NSObject *)0x32a9b4
js> [o test]
test1 test2
js> @teach o test { return [super test] + " test3" } @end
js> [o test]
test1 test2 test3

Index