Nu Class Reference

NuBridgedFunction

The Nu wrapper for imported C functions.

Superclass: NuOperator
Declared in: objc/Nu.h

Instances of this class wrap functions imported from C.

Because NuBridgedFunction is a subclass of NuOperator, Nu expressions that begin with NuBridgedFunction instances are treated as operator calls.

In general, operators may or may not evaluate their arguments, but for NuBridgedFunctions, all arguments are evaluated. The resulting values are then passed to the bridged C function using the foreign function interface (libFFI).

The C function's return value is converted into a Nu object and returned.

Here is an example showing the use of this class from Nu. The example imports and calls the C function NSApplicationMain.

(set NSApplicationMain
    (NuBridgedFunction
        functionWithName:"NSApplicationMain"
        signature:"ii^*"))

(NSApplicationMain 0 nil)


The signature string used to create a NuBridgedFunction must be a valid Objective-C type signature. In the future, convenience methods may be added to make those signatures easier to generate. But in practice, this has not been much of a problem.

Methods

+ (NuBridgedFunction *) functionWithName: (NSString *) name
signature: (NSString *) signature
Create a wrapper for a C function with the specified name and signature. The function is looked up using the dlsym() function and the wrapper is constructed using libFFI. If the result of this method is assigned to a symbol, that symbol may be used as the name of the bridged function.

in objc/Nu.h

- (id) evalWithArguments: (id) arguments
context: (NSMutableDictionary *) context
Evaluate a bridged function with the specified arguments and context. Arguments must be in a Nu list.

in objc/Nu.h

- (NuBridgedFunction *) initWithName: (NSString *) name
signature: (NSString *) signature
Initialize a wrapper for a C function with the specified name and signature. The function is looked up using the dlsym() function and the wrapper is constructed using libFFI. If the result of this method is assigned to a symbol, that symbol may be used as the name of the bridged function.

in objc/Nu.h