tomo/docs/README.md

169 lines
3.2 KiB
Markdown
Raw Normal View History

2024-08-18 21:23:02 -07:00
# Documentation
2024-08-18 15:30:40 -07:00
2024-08-18 21:23:02 -07:00
This is an overview of the documentation on Tomo.
## Topics
A few topics that are documented:
- [Compilation Pipeline](compilation.md)
2024-08-19 12:57:06 -07:00
- [Functions](functions.md)
2024-08-18 21:23:02 -07:00
- [Libraries/Modules](libraries.md)
- [Namespacing](namespacing.md)
- [Operator Overloading](operators.md)
2024-08-19 12:57:06 -07:00
- [Special Methods](metamethods.md)
2024-08-18 15:30:40 -07:00
## Types
2024-08-18 21:23:02 -07:00
Information about Tomo's built-in types can be found here:
2024-08-18 15:30:40 -07:00
- [Arrays](arrays.md)
- [Booleans](booleans.md)
- [Channels](channels.md)
2024-08-18 18:19:50 -07:00
- [Enums](enums.md)
2024-08-18 15:30:40 -07:00
- [Floating point numbers](nums.md)
- [Integer Ranges](ranges.md)
2024-08-18 18:19:50 -07:00
- [Integers](integers.md)
2024-08-19 11:41:04 -07:00
- [Languages](langs.md)
2024-09-09 02:00:12 -07:00
- [Paths](paths.md)
2024-08-18 15:30:40 -07:00
- [Sets](sets.md)
2024-08-18 18:19:50 -07:00
- [Structs](structs.md)
2024-08-18 15:30:40 -07:00
- [Tables](tables.md)
- [Text](text.md)
- [Threads](threads.md)
## Built-in Functions
2024-09-04 12:03:54 -07:00
### `ask`
**Description:**
Gets a line of user input text with a prompt.
**Usage:**
```markdown
ask(prompt:Text, bold:Bool = yes, force_tty:Bool = yes) -> Void
```
**Parameters:**
- `prompt`: The text to print as a prompt before getting the input.
- `bold`: Whether or not to print make the prompt appear bold on a console
using the ANSI escape sequence `\x1b[1m`.
- `force_tty`: When a program is receiving input from a pipe or writing its
output to a pipe, this flag (which is enabled by default) forces the program
to write the prompt to `/dev/tty` and read the input from `/dev/tty`, which
circumvents the pipe. This means that `foo | ./tomo your-program | baz` will
still show a visible prompt and read user input, despite the pipes. Setting
this flag to `no` will mean that the prompt is written to `stdout` and input
is read from `stdin`, even if those are pipes.
**Returns:**
A line of user input text without a trailing newline, or empty text if
something went wrong (e.g. the user hit `Ctrl-D`).
**Example:**
```markdown
>> ask("What's your name? ")
= "Arthur Dent"
```
---
2024-09-06 21:50:54 -07:00
### `exit`
**Description:**
Exits the program with a given status and optionally prints a message.
**Usage:**
```markdown
2024-09-15 12:33:47 -07:00
ask(message:Text = "", status:Int32 = 0[32]) -> Void
2024-09-06 21:50:54 -07:00
```
**Parameters:**
- `message`: If nonempty, this message will be printed (with a newline) before
exiting.
- `status`: The status code that the program with exit with.
**Returns:**
This function never returns.
**Example:**
```markdown
exit(status=1, "Goodbye forever!")
```
---
2024-08-18 15:30:40 -07:00
### `say`
**Description:**
Prints a message to the console.
**Usage:**
```markdown
2024-09-04 12:03:54 -07:00
say(text:Text, newline:Bool = yes) -> Void
2024-08-18 15:30:40 -07:00
```
**Parameters:**
- `text`: The text to print.
2024-09-04 12:03:54 -07:00
- `newline`: Whether or not to print a newline after the text.
2024-08-18 15:30:40 -07:00
**Returns:**
Nothing.
**Example:**
```markdown
2024-09-04 12:03:54 -07:00
say("Hello ", newline=no)
say("world!")
2024-08-18 15:30:40 -07:00
```
---
2024-09-12 00:20:17 -07:00
### `sleep`
**Description:**
Pause execution for a given number of seconds.
**Usage:**
```markdown
sleep(seconds: Num) -> Void
```
**Parameters:**
- `seconds`: How many seconds to sleep for.
**Returns:**
Nothing.
**Example:**
```markdown
sleep(1.5)
```
---
2024-08-18 15:30:40 -07:00
### `fail`
**Description:**
Prints a message to the console, aborts the program, and prints a stack trace.
**Usage:**
```markdown
fail(message:Text) -> Abort
```
**Parameters:**
- `message`: The error message to print.
**Returns:**
Nothing, aborts the program.
**Example:**
```markdown
fail("Oh no!")
```