Table of Contents
Previous Section
When you use compiled code in a WebObjects application, you have to implement your own main() function. This function creates the autorelease pool, adaptor, and application objects used in your application.
To implement a main() function:
For the Registration project, for example, create a file called Registration.m.
#import <WebObjects/WOWebScriptApplication.h>
#import <WebObjects/WOApplicationAdaptor.h>
#import <foundation/NSAutoreleasePool.h>
void main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
WOApplicationAdaptor *adaptor =
[[[WOApplicationAdaptor alloc] init] autorelease];
WOWebScriptApplication *application = [WOWebScriptApplication
sharedInstance];
[adaptor runWithApplication:application];
[pool release];
exit(0);
}
The function begins by creating an autorelease pool that's used for the automatic deallocation of objects that receive the autorelease message. Next, it creates an adaptor object that will be used to exchange data between the HTTP server and the WebObjects application object, which is created in the next statement. It then runs the adaptor and associates it with the newly created application. "Running" means that the adaptor will forward incoming requests from the server to the application and outgoing responses from the application to the server. The last statement releases the autorelease pool, which sends a release message to any object that has been added to the pool since the application began.
If you're using Project Builder, you do this by dragging the file into the Other Sources suitcase in your project.