Holds information, and controls, over a function in a scripting environment. More...
Public Member Functions | |
OutputValue | defaultFunction (const DataStack &stack) |
The default place holder function. Set by default. | |
Function (nkMemory::StringView name) noexcept | |
virtual | ~Function () |
nkMemory::StringView | getName () const |
void | addParameter (FUNCTION_PARAMETER_TYPE type, nkMemory::StringView userTypeName="") |
void | setFunction (FunctionCallback function) |
void | reset () |
Holds information, and controls, over a function in a scripting environment.
Usage is to declare the function in the environment, sets its callback and parameters. Whenever a script will call the function, it will check and fill with parameter the stack and call the callback. Callback can then return whatever it needs after processing, and this will be used within the environment.
Here is a high level overview of the usage, first creation and setup :
Callable from lua as :
That will execute this function :
And result in :
|
noexcept |
Constructor.
name | The name of the function. |
|
virtual |
Destructor.
nkMemory::StringView nkScripts::Function::getName | ( | ) | const |
void nkScripts::Function::addParameter | ( | FUNCTION_PARAMETER_TYPE | type, |
nkMemory::StringView | userTypeName = "" |
||
) |
Adds a parameter in the function signature. Parameters are expected in the order in which they are added within the Function. For instance, declaring :
Will cause the function to need to be called with two parameters, an int as the first one, and a string as the second one. Failure to do so will trigger an error.
As a result, parameters need to be declared through this method to make the runtime checks and data stack fill possible.
type | The parameter type. |
userTypeName | If user data, the type awaited. |
void nkScripts::Function::setFunction | ( | FunctionCallback | function | ) |
Sets the callback function when this function is called in script.
function | The function to call. |
void nkScripts::Function::reset | ( | ) |
Resets and starts back from an empty function.