callFunction()
Calls a specific function. The parameters of the called function are passed as parameters in callFunction().
Synopsis
anytype callFunction(string funcName[, <parameter1>[,
<parameter2>]] ...);
Parameters
Parameter | Meaning |
---|---|
funcName |
Name of the function to be called. This can be any function - CTRL function as well as a function written in C++. Keep in mind that the function name begins and ends with a double quote (string) and does not contain the parameter brackets. Example: int ms = callFunction("hour", t); |
parameter1, parameter2, ... | Parameters of the called function. |
Return value
Return value of the called function. The return value of the function callFunction() must be assigned to a variable. If the function is called without assigning the return value to a variable, the script is closed without a message. This also applies to the callFunction() within the DebugN() function.
Errors
Error if the given function does not exist or cannot be called (is private or wrong/missing parameters).
Description
Calls a specific function. The parameters of the called function are passed as parameters in callFunction().
Note that the stack trace contains the call of callFunction() only and not of the called function.
This function will not work correctly if used with functions of panels or panel references. The called functions will run in the wrong context, leading to problems (e.g. inaccurate addressing of objects).
It is not possible to directly use synchronized functions. Instead a workaround must be used:
Instead of declaring the function itself as synchronized, e. g.:
synchronized int someFunc()
{ ... }
define and use a "mutex" for synchronous calls to this function:
uint lock_someFunc;
int someFunc() synchronized(lock_someFunc)
{ ... }
The "mutex" can be of any type, for further information see documentation for "synchronized". Each function that should be synchronized separately will need its own "mutex" variable. Now the use of
int result = callFunction("someFunc");
will work as expected.
Example
main()
{
time t = callFunction("makeTime", 1999,8,13,13,40,10,50);
DebugN(t);
int ms = callFunction("hour", t);
DebugN(ms);
// 13
int f = callFunction("floor", 2.25);
DebugN(f);
// 2
}
Assignment
Availability
CTRL