rwlogo
Rogue Wave Views 5.6

Rogue Wave Views
Foundation Package API Reference Guide

Product Documentation:

Rogue Wave Views
Documentation Home

List of all members | Public Member Functions
IlvScriptFunction Class Referenceabstract

Scripting class. More...

#include <ilviews/base/script.h>

Inherits IlvValueInterface.

Public Member Functions

 IlvScriptFunction (IlvScriptContext *context, const char *functionName, IlvValueTypeClass *retType, IlInt nParams, IlInt reqParams,...)
 Constructor. More...
 
virtual IlBoolean call (IlvValue &retVal, IlInt count, IlvValue *args)=0
 Defines the function. More...
 

Detailed Description

Scripting class.

Library: display

The class IlvScriptFunction is an abstract class that you must derive to access C++ code from scripting languages.

See Also
IlvScriptContext.

Constructor & Destructor Documentation

IlvScriptFunction::IlvScriptFunction ( IlvScriptContext context,
const char *  functionName,
IlvValueTypeClass retType,
IlInt  nParams,
IlInt  reqParams,
  ... 
)

Constructor.

This constructor initializes a new instance of a subtype of the class IlvScriptFunction declaring a new function. This function can be accessed from the scripting language that you use, in the indicated context.

Parameters
contextThe script context where this function is defined.
functionNameThe name of this new function. The string is copied.
retTypeA pointer to the instance of the return type of this function.
nParamsThe maximum number of parameters that this function can take.
reqParamsSpecifies how many parameters are actually required, the other parameters being optional.

The ellipses must be replaced with pairs of nParams parameters. The first of the two parameters is a pointer to the expected parameter type, and the second is a string that names the parameter. The following function, for example, takes three parameters of the integer type and an optional parameter. It returns an integer.

class MyFunction
MyFunction(IlvScriptContext* context,
const char* functionName)
: IlvScriptFunction(context, functionName,
IlvValueIntType, 3, 2,
IlvValueIntType, "first",
IlvValueIntType, "second",
IlvValueIntType, "third")
{ .... }
};

Member Function Documentation

virtual IlBoolean IlvScriptFunction::call ( IlvValue retVal,
IlInt  count,
IlvValue args 
)
pure virtual

Defines the function.

This member function is the only one that must be implemented to perform the task for which the scripting function is designed. It is called by the script interpreter with the parameters provided by the user (the number and the types of arguments are implicitly checked). Let us suppose that the scripting function presented above adds the values of the first two parameters and divides the result by the third argument, if any. Here is how we would implement the call function:

MyFunction::call(IlvValue& ret, IlInt count, IlvValue* args)
{
ret = ((IlInt)args[0])+((IlInt)args[1]);
if (count == 3) { // Third parameter was provided
IlInt div = (IlInt)args[2];
if (div) // Is it a valid divider?
ret = (IlInt)ret/div;
else
return IlFalse; // Failure, Zero divide
}
return IlTrue;
}
Parameters
retValThe return value of this function.
countThe number of parameters provided to this function.
argsAn array of at least count values that are used as the parameters of the function.
Returns
IlTrue on success and IlFalse on failure.

© Copyright 2012, Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.