XII Release 0.1.0
Loading...
Searching...
No Matches
xiiConsoleFunctionBase Class Referenceabstract

Base class for all types of xiiConsoleFunction, represents functions to be exposed to xiiConsole. More...

#include <ConsoleFunction.h>

Inheritance diagram for xiiConsoleFunctionBase:
[legend]

Public Member Functions

 xiiConsoleFunctionBase (xiiStringView sFunctionName, xiiStringView sDescription)
 The constructor takes the function name and description as it should appear in the console.
 
xiiStringView GetName () const
 Returns the name of the function as it should be exposed in the console.
 
xiiStringView GetDescription () const
 Returns the description of the function as it should appear in the console.
 
virtual xiiUInt32 GetNumParameters () const =0
 Returns the number of parameters that this function takes.
 
virtual xiiVariant::Type::Enum GetParameterType (xiiUInt32 uiParam) const =0
 Returns the type of the n-th parameter.
 
virtual xiiResult Call (xiiArrayPtr< xiiVariant > params)=0
 Calls the function. Each parameter must be put into a xiiVariant and all of them are passed along as an array.
 

Additional Inherited Members

- Static Public Member Functions inherited from xiiNoBase
static const xiiRTTIGetStaticRTTI ()
 
- Protected Attributes inherited from xiiEnumerable< xiiConsoleFunctionBase >
xiiEnumerablem_pNextInstance
 

Detailed Description

Base class for all types of xiiConsoleFunction, represents functions to be exposed to xiiConsole.

Console functions are similar to xiiCVar's in that they can be executed from the xiiConsole. A console function can wrap many different types of functions with differing number and types of parameters. xiiConsoleFunction uses a xiiDelegate internally to store the function reference, so even member functions would be possible.

All console functions are enumerable, as their base class xiiConsoleFunctionBase is a xiiEnumerable class.

Console functions can have between zero and six parameters. The LuaInterpreter for xiiConsole only supports parameter types (unsigned) int, float/double, bool and string and uses the conversion feature of xiiVariant to map the lua input to the final function.

To make a function available as a console function, create a global variable of type xiiConsoleFunction with the proper template arguments to mirror its parameters and return type. Note that although functions with return types are accepted, the return value is currently always ignored.

void MyConsoleFunc1(int a, float b, xiiStringView sz) { ... }
xiiConsoleFunction<void ()> ConFunc_MyConsoleFunc1("MyConsoleFunc1", "()", MyConsoleFunc1);
int MyConsoleFunc2(int a, float b, xiiStringView sz) { ... }
xiiConsoleFunction<int (int, float, xiiString)> ConFunc_MyConsoleFunc2("MyConsoleFunc2", "(int a, float b, string c)", MyConsoleFunc2);
Implements the functionality of xiiConsoleFunctionBase for functions with different parameter types....
Definition ConsoleFunction.h:75
xiiStringView represent a read-only sub-string of a larger string, as it can store a dedicated string...
Definition StringView.h:34

Here the global function MyConsoleFunc2 is exposed to the console. The return value type and parameter types are passed as template arguments. ConFunc_MyConsoleFunc2 is now the global variable that represents the function for the console. The first string is the name with which the function is exposed, which is also used for auto-completion. The second string is the description of the function. Here we inserted the parameter list with types, so that the user knows how to use it. Finally the last parameter is the actual function to expose.

Member Function Documentation

◆ Call()

virtual xiiResult xiiConsoleFunctionBase::Call ( xiiArrayPtr< xiiVariant > params)
pure virtual

Calls the function. Each parameter must be put into a xiiVariant and all of them are passed along as an array.

Returns XII_FAILURE, if the number of parameters did not match, or any parameter was not convertible to the actual type that the function expects.

Implemented in xiiConsoleFunction< R(XII_LIST(P, ARG_COUNT))>.

◆ GetNumParameters()

virtual xiiUInt32 xiiConsoleFunctionBase::GetNumParameters ( ) const
pure virtual

Returns the number of parameters that this function takes.

Implemented in xiiConsoleFunction< R(XII_LIST(P, ARG_COUNT))>.

◆ GetParameterType()

virtual xiiVariant::Type::Enum xiiConsoleFunctionBase::GetParameterType ( xiiUInt32 uiParam) const
pure virtual

Returns the type of the n-th parameter.

Implemented in xiiConsoleFunction< R(XII_LIST(P, ARG_COUNT))>.


The documentation for this class was generated from the following file: