IO Module
This module provides basic input/output capabilities to the solus VM so that you can actually see what your program is doing. This also includes some other system info.
io.print
io.print(val: any)
Prints the str representation of any value to the console
Arguments
| Parameter | Type | Description |
|---|---|---|
val | any | Any value possible in solus |
Example
solus
io.print('Hello!');io.println
io.println(val: any)
Prints the str representation of any value to the console, followed by a newline character and flush
Arguments
| Parameter | Type | Description |
|---|---|---|
val | any | Any value possible in solus |
Example
solus
io.println('Hello, world!');io.time
io.time() -> f64
Returns the time in seconds since the UNIX epoch
Example
solus
val start = io.time();
do_work();
io.println($'Work took {io.time() - start}s');io.fread
io.fread(path: str) -> str|err
Attempts to read a file from the specified path
Arguments
| Parameter | Type | Description |
|---|---|---|
path | str | The relative file path |
Example
solus
var f = io.fread('test.cfg').unwrap();
# verify...
eval(f).unwrap();io.fwrite
io.fwrite(path: str, content: str) -> nil|err
Writes the provided string to a file at the specified path
Arguments
| Parameter | Type | Description |
|---|---|---|
path | str | The relative file path |
content | str | Contents to write to file |
Example
solus
io.fwrite('test.cfg', default.stringify(false)).unwrap();io.compile
io.compile(src: str, path: str) -> nil|err
Attempts to compile provided source into a function and then save it to a file at the provided path
Arguments
| Parameter | Type | Description |
|---|---|---|
src | str | Solus source to compile |
path | str | The relative file path |
Example
solus
io.compile({1, 2, 3}.stringify(), 'array.solu').unwrap();io.input
io.input(prefix: str) -> str
Get input from the user in a command line, printing a prefix before hand
Arguments
| Parameter | Type | Description |
|---|---|---|
prefix | str | The prefix to print before the prompt |
Example
solus
while !should_exit {
var i = io.input("> ");
if i == "!"
i = old_i;
if i != ""
io.println(catch([i]() eval(i)));
old_i = i;
}