Interpreter Mode

Interpreter mode enables you to send and execute any valid script statement at runtime, except for the declaration of new global variables.

An internal interpreter thread is created at the start of execution of each primary program. The interpreter socket (30020) accepts complete and valid URScript statements when a program is running. When interpreter mode is active, it compiles and links the received statements into the running program and executes them in the scope of the interpreter thread. These statements become part of the running program.

The scope of statements in interpreter mode is inherited from the scope from which interpreter mode was called. Declaring new global variables in interpreter mode is not supported.

When statements are sent at a faster rate than the interpreter can handle, they are queued in an internal buffer before they are appended to the running program.

When the last received statement is executed, the interpreter thread is idle until new statements are received.

Interpreter mode can be stopped by calling end_interpreter() over the interpreter mode socket, or by calling it from a thread in the main program. Interpreter mode also stops when the program is stopped.

Each statement must be sent on a single line. For example, the following multi-line statement:

def myFun():
mystring = "Hello Interpreter"
textmsg(mystring)
end

Must be formatted as follows:
def myFun(): mystring = "Hello Interpreter" textmsg(mystring) end

Use a newline character to end the statement. Multiple statements can be sent on a single line and are only accepted if all can be compiled.

Interpreter Mode replies

Received valid commands and statements are always acknowledged with a reply on the socket in the following form:
ack: <id>: <statements>

Here, <id> is a consecutively unique ID for the received <statement>.

If a program is not running, or the statement results in a compilation or linker error, the interpreter replies with a discard message:
discard: <reason>: <statement>.

Note: There is an upper limit to the size of the interpreted statements per interpreter mode. To avoid reaching that limit, you can call clear_interpreter() to clear everything interpreted into the current interpreter mode.

Important: Each time a statement is interpreted, the size and complexity of the program increase if interpreter mode is not cleared either on exit or with clear_interpreter(). Avoid creating programs that are too large.