Program/StdOut
The Program Object represents the currently running app. This object offers functionality to execute system commands, include sub programs, read arguments and more. All system related functions.
StdOut
Out is the standard output object. It basically has two methods: write: and stop. The write: message is used to send a string to stdout, the stop message prints a newline character. Instead of stop you can also use \n.
Example:
Out write: ['Hello World'], stop.
result:
Hello World
Modules/Plugins
The world of Xoscript can be expanded with new system objects, by installing modules . A new system object can be added to the world of Xoscript by placing the module file (usually a file with the suffix .so or .dll) into the mods folder.
When you send a message to the object that is made available through the plugin module, it will be automatically loaded by Xoscript.
Reflection
There are various ways for system exploring during program execution. Xoscript holds a couple of methods to detect which objects are present and to which messages these objects respond. Firstly, each object can be asked what type it is, however types in Xoscript are malleable and therefore unreliable.
It is also possible to ask the Program object if a given object is already present in the program:
Program Tool true: { ... }.
In case of an object name which consists of one single symbol, it is best to apply the following notation to avoid confusion:
Program find: ['X'], true: { ... }.
Besides asking about objects, it is equally possible to ask the Program object about messages. For instance, it can be asked if the object Number knows the message between:and:, in the way as is illustrated below:
Program Number: ['between:and:'], stop.
[ Program ] memory: [Number]
Example:
Program memory: 8 MB.
Program memory: 500 KB.
Result:
[ Program ] os: [ String ]
Example:
#Linux
>> x := Program os: Command uname.
Out write: x.
Result:
[ Program ] argument: [ Number ]
Example:
>> x := Program argument: 1.
Out write: x, stop.
Result:
[ Program ] number.
Example:
>> x := Program number.
Out write: x, stop.
Result:
[ Program ] string
Example:
>> x := Program string.
Out write: x, stop.
Result:
[ Program ] use: [ String ]
Example:
>> f := File new: (Path /tmp: ['x.ctr']).
f write: ['>> x := 123.'].
Program use: (Path /tmp: ['x.ctr']).
Out write: x, stop.
Result:
[ Program ] [ String ]
Example:
Out write: Program Object, stop.
Out write: Program Dream, stop.
Result:
[ Program ] find: [ String ]
Example:
Out write: (Program find: ['✎']), stop.
Out write: (Program find: ['Q']), stop.
Result:
[ Program ] [ String ]: [ String ]
Example:
Out write: (Program ✎: ['AAA']), stop.
Out write: (Program Program: ['test']), stop.
Result:
[ Program ] arguments
Example:
Out write: Program arguments, stop.
Result:
[ Program ] end
Example:
Out write: ['1..2..3..'], stop.
Program end.
Out write: ['4..5..6..'], stop.
Result:
[ Program ] setting: [ String ]
Example:
#Linux
>> x := Program setting: ['SHELL'].
Out write: x, stop.
Program setting: ['TEST'] value: ['123'].
>> x := Program setting: ['TEST'].
Out write: x, stop.
Result:
[ Program ] setting: [ String ] value: [ String ]
Example:
#Linux
>> x := Program setting: ['SHELL'].
Out write: x, stop.
Program setting: ['TEST'] value: ['123'].
>> x := Program setting: ['TEST'].
Out write: x, stop.
Result:
[ Program ] ask
Example:
#Out write: Program ask, stop.
#@result
#~$ hello_
#hello
#~$_
Result:
[ Program ] ask password
Example:
#Out write: Program ask-password, stop.
#@result
#~$ ****_
#1234
#~$_
Result:
[ Program ] input
Example:
Server init.
>> message := ['this is a string to be encrypted!'].
>> key := ['secret123!'].
>> vault := Vault new: ['myvault'].
>> encrypted := vault encrypt: message key: key.
>> decrypted := vault decrypt: encrypted key: key.
Out
write: ['Message:'], stop
write: message, stop
write: ['Decrypted:'], stop
write: decrypted, stop.
Result:
[ Program ] flush
Example:
Out write: ['Flush stdout buffer.'], stop.
Program flush.
Result:
[ Program ] error: [ String ]
Example:
Program error: ['123'].
Result: