std::sys
| Item | Summary |
|---|---|
arg | Returns the command-line argument at index, or null if there isn’t one |
exit | Ends the program immediately with the exit code code |
stdin | Reads standard input until it ends and returns all of it as one string |
file | Returns the absolute path of the source file that contains the call |
Functions
arg
fn arg(index: int) -> str?
Returns the command-line argument at index, or null if there isn’t one. When the script is
run with the mimas command, index 0 is the script’s path as it was typed, and the arguments
after -- start at index 1.
use std::sys;
// run as `mimas tool.mim -- input.txt`
let path = sys::arg(1) ?? "default.txt"; // "input.txt"
exit
fn exit(code: int) -> !
Ends the program immediately with the exit code code. Nothing after the call runs.
use std::sys;
if sys::arg(1) == null {
print("usage: tool <file>");
sys::exit(1);
}
exit ends the whole process. When mimas is embedded in a larger program, that program exits
as well.
stdin
fn stdin() -> str!
Reads standard input until it ends and returns all of it as one string. Raises if the input can’t be read or isn’t valid UTF-8.
Input piped in from another program ends when that program finishes. In a terminal, it ends when you press Ctrl+D (Ctrl+Z then Enter on Windows).
use std::sys;
// run as `echo "a b c" | mimas count.mim`
let words = sys::stdin()!.trim().split(" ");
print(words.len()); // 3
file
fn file() -> str
Returns the absolute path of the source file that contains the call. For a script compiled from a string instead of a file, it’s the name the host gave that source.
Use it to find files stored next to the script (relative paths in std::fs start from the
working directory instead).
use std::sys;
print(sys::file()); // /home/ada/projects/game/main.mim