When we define a method with F-Script (as shown here and here), it gets automatically registered in the Objective-C runtime. Indeed, from the point of view of the runtime, the new method is just like any other Objective-C method. Among other things, this means that it can be invoked from Objective-C code.
This also manifests in the syntax of F-Script itself. From the outside, nothing looks more like an Objective-C method than a F-Script method:
Objective-C method
- (float) doSomethingWithFoo:(int)x bar:(Bar *)y
{
... Objective-C code ...
}
F-Script method
- (float) doSomethingWithFoo:(int)x bar:(Bar *)y
{
... F-Script code ...
}
In the example above, we make use of explicit typing in the method signature. This is particularly useful when we want to hand out a F-Script object to some Objective-C code that call us back by invoking a method taking or returning non-object values. Indeed, the method we define must know what are the types of its arguments and return value.
Of course, since F-Script is a pure object language, actual values passed as arguments are automatically mapped to objects, and the returned object is automatically mapped to the data type promised to the caller by the signature.
Here is a list of types supported at the time of this writing:
- id
- Class
- SEL
- BOOL
- _Bool
- char
- unsigned char
- short
- unsigned short
- int
- unsigned int
- long
- unsigned long
- long long
- unsigned long long
- NSInteger
- NSUInteger
- float
- double
- CGFloat
- NSRange
- NSPoint
- NSRect
- NSSize
- CGPoint
- CGRect
- CGSize
- void *
We can also use a class name followed by a *, as in Objective-C (e.g. NSString *).
To specify pointers we can put as many * as needed after a type (e.g. unsigned int **).
Finally, we use void to indicate that a method returns nothing.
By default, in the absence of an explicit type, id is assumed, as in Objective-C.
To use these capabilities, get the latest alpha version of F-Script 2.0.