s |
focus search bar ( enter to select, ▲ / ▼ to change selection) |
g c |
go to c_api |
g g |
go to getting_started |
g t |
go to toy_api |
h |
toggle this help ( esc also exits) |
To help you start using Toy as fast as possible, here are the most useful elements of the language. Not everything available is listed, but this should let you start coding right away.
The print
keyword takes one value as a parameter, which is sent to stdout by default.
The value can be redirected elsewhere using the debug C API.
print "Hello World!";
The assert
keyword takes two values as parameters, separated by a comma. If the first value is null
or false
, the second parameter is sent to stderr by default. Otherwise, this statement is ignored.
The second value, which is replaced by a default error message if omitted, can be redirected elsewhere using the debug C API.
The generation of assert statements can be disabled using the parser C API.
assert 1 < 2;
assert null, "Hello world!";
Values can be stored in variables, by specifying a name with the var
keyword. The name can also be declared with a type, which restricts what kind of value can be stored in the name. Types are optional, and defaults to any
when not used.
var answer = 42;
var question: string = "How many roads must a man walk down?";
To make a variable unchangeable after declaration, you can add the const
keyword after the type.
var quote: string const = "War. War never changes.";
The usable types are as follows:
type | name | description |
---|---|---|
bool |
boolean | Either true or false . |
int |
integer | Any whole number, representable by a signed 32-bit integer. |
float |
float | A decimal number, represented by 32-bits for floating-point arithmetic. |
string |
string | A piece of text, supports UTF-8. |
array |
array | A series of values stored in sequential memory. |
table |
table | A series key-value pairs stored in such a way that allows for fast lookups. Booleans, functions and opaques can’t be used as keys. |
function |
function | A chunk of code to be called. It can take multiple parameters, and provide multiple return values. Unlike other variables, functions are declared with the fn keyword. |
opaque |
opaque | The contents of this value is unusable in the script, but can be passed from one API to another. |
any |
any | The default type used when none is specified. This type can hold any value. |
Note: Functions and opaques are not yet implemented at the time of writing.
Watch this space.
if-then-else
while
for //not yet implemented
continue
break
Watch this space.
Watch this space.
Watch this space.
Theme adapted from programming pages theme v0.5.22 (https://github.com/pixeldroid/programming-pages) |
s |
focus search bar ( enter to select, ▲ / ▼ to change selection) |
g c |
go to c_api |
g g |
go to getting_started |
g t |
go to toy_api |
h |
toggle this help ( esc also exits) |