startScript()

The startScript function starts a script, which is independent from the script from where it was started.

Synopsis

int startScript(string|int script [, dyn_string dollars [, string func, [dyn_anytype args]]]);

Parameters

Parameter Description
script The executes script
dollars The $parameter of the script
func The "func" optional argument in startScript() tells CTRL which function in the script to start. By default it is the "main" function.
arg "args" is the list of arguments passed to the started function. Note that the given dyn_anytype is internally split and passed as separate arguments to the started function, e.g. passing a dyn_anytype with 3 items would need a main() function with 3 arguments.

Return value

success 0, else -1

Errors

Invalid Arguments

Description

The startScript function starts a script, which is independant from the script from where it was started, which means: when the initiating script is destroyed, the newly started script is not affected and stays alive.

However, the started script will delete itself when startScript() is only given a single string argument and the new script has finished execution.

startScript() returns the script-id of the started script, which can be reused to restart the script again when it is still available (e.g. when it deleted itself due to startScript() with only a single string argument and the script has already completed, it's no longer available).

Example

startScript("main() { DebugN(123); }");  will delete the new script after the Debug output


int id = startScript("main() { DebugN(123); }", "");


// will not delete the new script after the Debug output and the script can be started again by calling:


startScript(id);

In contrast to execScript() and evalScript(), the initiating thread will not be blocked when using startScript(). The new script will be started and both threads (the initiating thread and the new main thread) will run in parallel.

To stop and delete a script which was started by startScript() one can use stopScript(id);

If a script started as "keep when done" (by passing more than 1 argument to startScript()), one has to explicitely use stopScript() to delete the script and to free the associated memory, otherwise the script exists and the memory is used until the whole manager stops.

Assignment

Miscellaneous Functions

Availability

CTRL