evalScript()

Allows to execute a script during runtime and to write the return value of the script in retVal.

Synopsis

int evalScript(anytype &retVal, string script,[ dyn_string dollars [,<type> <arg> ...]] )

Parameters

Parameter Meaning
retVal Return value of the executed script
script The executes script
dollars The $parameter of the script
arg The parameters of any existing main function

Return value

If the execution was successful, the function returns 0 or in the event of an error, -1.

Error

An error can be, for example, a syntax error in the script or a missing main function.

Description

The function executes the defined script with the $parameters and returns the return value of the main function in retVal.

evalScript() can not be used to call a function from the calling script (c.f. example 1).

When using Object Oriented Scripting (CTRL++) the scope accessibility must be considered as otherwise crashes inside of your tests might occur!

Example 1

This example shows how evalScript() can NOT be used.

main()
{
  evalScript(ret, "string main(){ return myFunc();}", makeDynString());
}
string myfunc()
{
  return "A";
}

Example 2

The function evalScript() calls a script inside the main-function and the returning values are sent to the log viewer.

main()
{
  int sum;
  int rc = evalScript(sum,
      "int main(int a, int b)" +
      "{" +
      "  int val;" +
      "  val = 3;" +
      "  DebugN(\"$ Val:\", $val1 + \" val:\", a + b );" +
      + "  return a + b;"
      "}",
      makeDynString("$val1:12345"), 17, 8);
      DebugN("Return:" + sum);
 }

Assignment

Miscellaneous functions, waiting CONTROL functions

Availability

CTRL