The DLR Shell output supports both plain text output messages and output tables. The output is entirely defined by the DLR script that is executed. This section explains how to format DLR Shell output.
Use DLR output functions such as print to write data to the output. The DLR engine created by Silverlight Spy redirects the output stream directly to the output window of the DLR Shell.
When the result of the DLR code consists of a single value, it is also possible to omit the usage of writing to the output stream and let Silverlight Spy serialize the result and send it to the output window.
When the result of a single DLR execution contains both output stream print results and returns a value, the output stream and the returned value are concatenated as the following Python sample demonstrates.
print 'hello world' 3+3 #result is concatted # Result: # hello world # 6
Next to plain text output the DLR Shell supports output tables. Output can include up to eight output tables, where each table appears in its own tab in the output pane. An output table is visualized by a sortable grid, and as such provides a convenient method for displaying DLR output. Figure 1 displays an output table example.
A DLR output table is a 2-dimensional set of data consisting of N columns and M rows. A row does not need to provide data for each column, the DLR output table automatically adjusts the number of columns based on the actual row data provided.
DLR output tables are created by programmatically adding them to the output. The output is represented by a global variable named out and is always available to all scripts in the DLR shell. The out is a variable of type DlrOutput and exposes methods for managing DLR output tables.
The following Python code snippet demonstrates the use of adding two tables to the output. Table 2 defines a number of columns which subsequently appear in the output pane as is demonstrated in figure 2.
out.AddTable('Table 1') out.AddTable('Table 2', 'Column 1', 'Column 2')
Specifying column names is entirely optional, the number of columns of an output table is automatically adjusted to the actual provided row data.
Add row data to an output table by using the AddRow method. AddRow takes any number of arguments. Each argument specifies a value for a column and the rows of a single table do not need to have the same amount of cells. The following Python code snippet demonstrates the use of adding rows to an output table. The output is demonstrated in Figure 3.
table = out.AddTable('Table 1') table.AddRow('a') table.AddRow('a','b') table.AddRow('a','b','c')
The global out variable contains a number of methods for managing DLR output. See for more details on its functionality.