evalScriptRestricted()

Allows to execute a script during runtime and to write the return value of the script in target. Compared to the unrestricted function evalScript() only a more limited set of functions is allowed to provide better security.

Synopsis

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

Parameters

Parameter Meaning
target 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

Like evalScript() the function executes the defined script with the $parameters and returns the return value of the main function in target. However only a limited amount of functions may be used.

  • UI-functions

  • functions from CTRL-extensions

function-types that may not be used:

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 = evalScriptRestricted(sum,
      "int main(int a, int b)" +
      "{" +
      "  int val;" +
      "  val = 3;" +
      "  DebugN(\"$ Value:\", $val1 + \" val:\", a + b );" +
      "}",
      makeDynString("$val1:12345"), 17, 8);
  DebugN(rc, sum);
}

Assignment

Miscellaneous functions, waiting CONTROL functions

Availability

CTRL