ftp.nice.ch/pub/next/developer/objc/api/QuestorAPI.3.2.s.tar.gz#/Questor_API/ExternalFunctions/Source/LibraryDemo

English.lproj/
 
LibraryDemo.h
[View LibraryDemo.h] 
LibraryDemo.m
[View LibraryDemo.m] 
Makefile
 
Makefile.postamble
 
Makefile.preamble
 
PB.project
 
README
 
my_addin_function.folder/
 

README

//
//	Xanthus
//	Copyright (c) 1992-95 Bjorn Backlund.  
//	All rights reserved. 
//


LibraryDemo

This small project implements a small "library bundle" which
shows a technique how to put code which should be used by several
Questor addin-functions in a common bundle which is loaded by the first
addin which is loaded into Questor.

The LibraryDemo project implements one small class - LibraryDemo - which should implement the common code. 

Instead of writing common C functions, the addin-implementors should use common methods defined in the common bundle class. Instead of calling common C functions (e.g. foobar(1,2)), the addins should send messages to the common bundle class - e.g. LibraryDemo.

This example uses class methods, but nothing prevents you from using normal methods.

	
Example usage in a addin class:
------------------------------------------------------------------------

@implementation my_addin_function

- libClass;
{
	const char *libFolder = "THE FULL PATH TO THE LIB BUNDLE";
	id libBundle = nil;
	static id libClass = nil;
	
	if(libClass != nil) return libClass;
	
    // Example libFolder:	/Library_Bundles/LibraryDemo.bundle
    
    // Get a bundle for the library folder
	
	libBundle = [[NXBundle alloc] initForDirectory: libFolder];
	
    // Force class to to loaded
	
	libClass = [libBundle classNamed: "LibraryDemo"];
	
	if(libClass == nil)
		NXLogError("ERROR: No class LibraryDemo in %s", libFolder);
		
	return libClass;
}



- (void *)runFunction: (void *)frame;
{
	double x, y, result;
	int xType, yType;
	
	xType = XQ_ArgType(frame, 0);
	yType = XQ_ArgType(frame, 1);
	
	if(xType != XQ_DOUBLE_ARG) {
		XQ_RaiseArgTypeError(frame, 0, XQ_DOUBLE_ARG);
	}
	
	if(yType != XQ_DOUBLE_ARG) {
		XQ_RaiseArgTypeError(frame, 1, XQ_DOUBLE_ARG);
	}
	
	x = XQ_GetDoubleValue(frame, 0);
	y = XQ_GetDoubleValue(frame, 1);
	
    // Call the library routine foobar
	
	result = [[self libClass] foobar: x : y];
	
	return XQ_CreateDoubleValue(frame, result);
}

+ (const char *)functionName;
{
	return "my_addin_function";
}

+ (const char *)categoryName;
{
	return "demo_category";
}

- (const char *)argumentNameNo:(int)index;
{
	switch(index) {
	case 0 : 
		return "x";
	case 1 : 
		return "y";
	}
	
	return "<should never be seen>";
}

- (int)minArg;			
{
	return 2;
}

- (int)maxArg;				
{
	return 2;
}

- (int)formalCount;
{
	return 2;
}

- (int)argType:(int)index;	
{
	switch(index) {
	case 0 : 
		return XQ_EVAL;
	case 1 : 
		return XQ_EVAL;
	}
	return XQ_EVAL;
}

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.