Webscript for objective-c developers – Apple WebObjects 3.5 User Manual

Page 183

Advertising
background image

WebScript for Objective-C Developers

183

The following example is a simple category of WORequest that gets the
sender’s Internet e-mail address from the request headers (“From” key)
and returns it (or “None”).

@implementation WORequest(RequestUtilities)
- emailAddressOfSender {

NSString *address = [self headerForKey:@"From"];
if (!address) address = @"None";
return address;

}
@end

Elsewhere in your WebScript code, you invoke this method on WORequest
objects just as you do with any other method of that class. Here’s an
example:

- takeValuesFromRequest:request inContext:context {

[super takeValuesFromRequest:request inContext:context];
[self logWithFormat:@"Email address of sender: %@",

[request emailAddressOfSender]];

}

The category must be included either at the end of a component’s script file
(that is, a script file within a

.wo

) or it must be included in a scripted class’s

stand-alone script file. Do not place categories in the application or session
script.

WebScript for Objective-C Developers

WebScript uses a subset of Objective-C syntax, but its role within an
application is significantly different. The following table summarizes some
of the differences.

Objective-C

WebScript

Is compiled

Is interpreted

Supports primitive C data types

Supports only the class type

Performs type checking at compiled time

Never performs type checking

Requires method prototyping

Doesn’t require method prototyping (that is, you don’t

declare methods before you use them)

Usually involves a .h and a .m file

Stands alone (unless inside of a component directory)

Supports all C language features

Has limited support for C language features; for example,

doesn’t support structures, pointers, enumerations, or
unions

Advertising