CAOS (command)

CAOS is a CAOS function which injects code.

Usage
Syntax: CAOS inline (int) parented (int) p1 (anything) p2 (anything) commands (string) throw (int) catch (int) report (variable)

This executes the code contained in commands in a new virtual machine. If inline is non-zero, the local environment of the current script will be promoted to the new script. If parented is non-zero, FROM and OWNR will be propagated too, otherwise it will be run orphaned like an install script. p1 and p2 are sent to the script as _P1_ and _P2_ regardless of inline. Anything sent to the output stream by commands is returned as a string.

According to the CAOS documentation, if catch is non-zero the command will catch errors, return "###" and set report to the error as a string. However, experience appears to show that CAOS does this whatever the value of catch is.

throw is even more mysterious, but according to the documentation, if set to non-zero it will throw exceptions; otherwise it will return "***" on an exception and set report to the appropriate offset for the "caos" tag in CAOS.catalogue.

Note that all code in commands is run as non-blockable, i.e. INST.

Examples
The following can be used to allow arbitrary CAOS input, catching exceptions and errors and sending the result to the output stream. In an agent one would probably send to a text part instead. SETS va01 CAOS 0 0 0 0 va00 0 1 va02 DOIF va01 eq "***" DOIF va02 lt REAN "caos" SETS va01 READ "caos" va02 ELSE SETS va01 "Unknown exception occurred, ID " ADDS va01 VTOS va02 ENDI ELIF va01 eq "###" SETS va01 va02 ENDI OUTS va01
 * catch text entry, store in va00.