//
//	Xanthus
//	Copyright (c) 1992, 1993, 1994 Xanthus International AB.  
//	All rights reserved. 
//


#import <math.h>

#import "XQ_UserFunction.h"


@interface demo1:XQ_UserFunction
@end




@implementation demo1

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

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

- (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;
}

- (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);
	
	result = sqrt(x*x + y*y);
	
	return XQ_CreateDoubleValue(frame, result);
}

@end
