Skip to content

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

ParameterTypeDescription
valanyAny 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

ParameterTypeDescription
valanyAny 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

ParameterTypeDescription
pathstrThe 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

ParameterTypeDescription
pathstrThe relative file path
contentstrContents 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

ParameterTypeDescription
srcstrSolus source to compile
pathstrThe 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

ParameterTypeDescription
prefixstrThe 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;
}