mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
docs: spelling mistakes correction
This commit is contained in:
@@ -12,19 +12,19 @@ import math;
|
||||
|
||||
### PI: float
|
||||
|
||||
This constant represents the ratio of a circle's circumference to its diameter. It's value is approximately `3.14159265358979323846`.
|
||||
This constant represents the ratio of a circle's circumference to its diameter. Its value is approximately `3.14159265358979323846`.
|
||||
|
||||
### E: float
|
||||
|
||||
This constant represents Euler's number, the base of natural logarithms. It's value is approximately `2.71828182845904523536`.
|
||||
This constant represents Euler's number, the base of natural logarithms. Its value is approximately `2.71828182845904523536`.
|
||||
|
||||
### EPSILON: float
|
||||
|
||||
This constant represents the acceptable amount of error when comparing floats with the functions provided by this library (see [Defined Comparison Functions](#defined-comparison-functions)). It's default value is `0.000001`.
|
||||
This constant represents the acceptable amount of error when comparing floats with the functions provided by this library (see [Defined Comparison Functions](#defined-comparison-functions)). Its default value is `0.000001`.
|
||||
|
||||
### NAN: float
|
||||
|
||||
This constant represents "Not-a-Number", often returned when a calculation is impossible e.g. `sqrt(-1)`.
|
||||
This constant represents "Not-a-Number", often returned when a calculation is impossible, e.g. `sqrt(-1)`.
|
||||
|
||||
### INFINITY: float
|
||||
|
||||
@@ -124,4 +124,4 @@ This function returns true if `x` is Infinite, otherwise it returns false.
|
||||
|
||||
### epsilionCompare(x, y): bool
|
||||
|
||||
This function returns true if `x` and `y` are within `EPSILON` of each other, otherwise it returns false. This is very useful for compairing floating point values.
|
||||
This function returns true if `x` and `y` are within `EPSILON` of each other, otherwise it returns false. This is very useful for comparing floating point values.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
# Quick Start Guide
|
||||
|
||||
This guide is intended to get you writing Toy code as fast as possible. As such, it's more of a reference for experienced coders to know what is available and what isn't.
|
||||
@@ -23,7 +24,7 @@ var f = 3.14;
|
||||
var s = "Hello world";
|
||||
```
|
||||
|
||||
Numbers (both integers and floats) can be delimited with underscores (`_`), to break them up visually e.g. `100_000`.
|
||||
Numbers (both integers and floats) can be delimited with underscores (`_`), to break them up visually, e.g. `100_000`.
|
||||
|
||||
Strings can be 4096 characters long, and the following characters can be escaped: `\n`, `\t`, `\\` and `\"`.
|
||||
|
||||
@@ -122,7 +123,7 @@ greeting[0:4] = "Goodnight"; //changes greeting to equal "Goodnight world"
|
||||
|
||||
## External Libraries
|
||||
|
||||
The host may, at it's own discretion, make external libraries available to the scripts. To access these, you can use the `import` keyword:
|
||||
The host may, at its own discretion, make external libraries available to the scripts. To access these, you can use the `import` keyword:
|
||||
|
||||
```
|
||||
import standard;
|
||||
@@ -199,4 +200,3 @@ Other operators used throughout the language are: the assignment, colon, semicol
|
||||
```
|
||||
= : ; , . ...
|
||||
```
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
# Random Library
|
||||
|
||||
The random library offers a number of functions geared towards producing pseudorandom values. This library has a concept called "generators", which are opaque objects used to generate a sequence of numbers from an initial integer seed. A seed can be generated from most values using the standard library `hash` function.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
# Runner Library
|
||||
|
||||
The runner library is used to execute one script from inside another. It also has functions that allow you to retrieve variables from the other script.
|
||||
@@ -21,7 +22,7 @@ This function does a lot of work:
|
||||
* It validates the file path using the drive syntax
|
||||
* It reads in the source code of the script file
|
||||
* It compiles the source script into bytecode
|
||||
* It constructs and intializes an Interpreter
|
||||
* It constructs and initializes an Interpreter
|
||||
* It packages it all into an opaque variable and returns it
|
||||
|
||||
### loadScriptBytecode(path: string): opaque
|
||||
@@ -31,7 +32,7 @@ This is used to load an external bytecode file into an opaque variable.
|
||||
This function does a lot of work:
|
||||
|
||||
* It validates the file path using the drive syntax
|
||||
* It constructs and intializes an Interpreter
|
||||
* It constructs and initializes an Interpreter
|
||||
* It packages it all into an opaque variable and returns it
|
||||
|
||||
Note: This function resembles `loadScript()`, but skips the compilation step.
|
||||
@@ -58,4 +59,4 @@ This function frees a script's resources, cleaning up any memory that is no long
|
||||
|
||||
### checkScriptDirty(self: opaque): bool
|
||||
|
||||
This function returns true of the script is "dirty", otherwise it returns false.
|
||||
This function returns true if the script is "dirty", otherwise it returns false.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
# Standard Library
|
||||
|
||||
The standard library offers a number of miscellaneous utility functions, which can be used for various purposes. These are the most commonly used functions, so the standard library is almost certain to be included in the host program.
|
||||
@@ -57,19 +58,19 @@ This function returns the value of any integer or float passed in, rounded to th
|
||||
|
||||
This function expects an integer or float as the value for `self`.
|
||||
|
||||
If `self` is below 0, this function returns -1. Otherwise it returns 1.
|
||||
If `self` is below 0, this function returns -1. Otherwise, it returns 1.
|
||||
|
||||
### normalize(self): int
|
||||
|
||||
This function expects an integer or float as the value for `self`.
|
||||
|
||||
If `self` is below 0, this function returns -1. Otherwise if `self` is above 0, this function returns 1. Otherwise it returns 0.
|
||||
If `self` is below 0, this function returns -1. Otherwise, if `self` is above 0, this function returns 1. Otherwise it returns 0.
|
||||
|
||||
### clamp(value, min, max): any
|
||||
|
||||
This function expects integers or floats as the values for `value`, `min`, and `max`.
|
||||
|
||||
If `value` is smaller than `min`, this function will return `min`. Otherwise, if `value` larget than `max`, it will return `max`. Otherwise, it will return `value`.
|
||||
If `value` is smaller than `min`, this function will return `min`. Otherwise, if `value` larger than `max`, it will return `max`. Otherwise, it will return `value`.
|
||||
|
||||
### lerp(start, end, amount): any
|
||||
|
||||
@@ -81,23 +82,23 @@ This function will return the value of `start` adjusted towards the value of `en
|
||||
|
||||
### concat(self, other): any
|
||||
|
||||
This function only works when self and other are matching compounds (both arrays, dictionaries or strings). It returns a new compound of that kind, with the content of `other` appended to the content of `self`.
|
||||
This function only works when self and others are matching compounds (both arrays, dictionaries or strings). It returns a new compound of that kind, with the content of `other` appended to the content of `self`.
|
||||
|
||||
### containsKey(self: dictionary, key): bool
|
||||
|
||||
This function returns `true` if `self` contains the given `key`, otherwise it returns false.
|
||||
This function returns `true` if `self` contains the given `key`; otherwise, it returns false.
|
||||
|
||||
### containsValue(self, value): bool
|
||||
|
||||
This function returns `true` if `self` contains the given `value`, otherwise it returns false.
|
||||
This function returns `true` if `self` contains the given `value`; otherwise, it returns false.
|
||||
|
||||
### every(self, func: fn): bool
|
||||
|
||||
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, until `func` returns `false`, at which point this function returns `false`. Otherwise this function returns `true`.
|
||||
This function takes either an array or a dictionary as the `self` argument and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, until `func` returns `false`, at which point this function returns `false`. Otherwise, this function returns `true`.
|
||||
|
||||
### forEach(self, func: fn)
|
||||
|
||||
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time.
|
||||
This function takes either an array or a dictionary as the `self` argument and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. The contents of `self` are passed into `func` one element at a time.
|
||||
|
||||
```
|
||||
import standard;
|
||||
@@ -113,7 +114,7 @@ a.forEach(p); //prints 1, 3, and 5 to stdout
|
||||
|
||||
### filter(self, func: fn): any
|
||||
|
||||
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, and the function returns a new compound for every element that `func` returned a truthy value for.
|
||||
This function takes either an array or a dictionary as the `self` argument and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, and the function returns a new compound for every element that `func` returned a truthy value for.
|
||||
|
||||
### getKeys(self: dictionary): [any]
|
||||
|
||||
@@ -129,7 +130,7 @@ This function returns the first index within `self` that is equal to `value`, or
|
||||
|
||||
### map(self, func: fn): any
|
||||
|
||||
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. It returns an array with the results of each call - the order of the results when called on a dictionary are undefined.
|
||||
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. It returns an array with the results of each call - the order of the results when called on a dictionary is undefined.
|
||||
|
||||
```
|
||||
import standard;
|
||||
@@ -145,13 +146,13 @@ print a.map(increment); //prints [2,3,4];
|
||||
|
||||
### reduce(self, default: any, func: fn): any
|
||||
|
||||
This function takes either an array or a dictionary as the `self` argument, a default value, and a function as `func`. The argument `func` takes three arguments - the first is the accumulator, the second is the index/key and the third is the value. It applies the given function to every element of the array/dictionary, passing the result of each call as the accumulator to the next (the default value is used for the first call). Finally, the final value of the accumulator is returned to the caller.
|
||||
This function takes either an array or a dictionary as the `self` argument, a default value, and a function as `func`. The argument `func` takes three arguments - the first is the accumulator, the second is the index/key, and the third is the value. It applies the given function to every element of the array/dictionary, passing the result of each call as the accumulator to the next (the default value is used for the first call). Finally, the final value of the accumulator is returned to the caller.
|
||||
|
||||
```
|
||||
import standard;
|
||||
|
||||
fn f(acc, k, v) {
|
||||
return acc + v;
|
||||
return acc + v;
|
||||
}
|
||||
|
||||
var a = [1, 2, 3, 4];
|
||||
@@ -161,11 +162,11 @@ print a.reduce(0, f); //prints "10"
|
||||
|
||||
### some(self, func: fn): bool
|
||||
|
||||
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, until `func` returns `true`, at which point this function returns `true`. Otherwise this function returns `false`.
|
||||
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, until `func` returns `true`, at which point this function returns `true`. Otherwise, this function returns `false`.
|
||||
|
||||
### sort(self: array, func: fn)
|
||||
|
||||
This function takes an array as the `self` argument, and a comparison function as `func`. The argument `func` must take two arguments, and return a truthy or falsy value. The contents of the array in `self` are sorted based on the results of `func`, as though the function were the less comparator function.
|
||||
This function takes an array as the `self` argument, and a comparison function as `func`. The argument `func` must take two arguments and return a truthy or falsy value. The contents of the array in `self` are sorted based on the results of `func`, as though the function was the less comparator function.
|
||||
|
||||
```
|
||||
import standard;
|
||||
@@ -211,3 +212,5 @@ This function is identical to `trim(self, trimChars)`, except it is only applied
|
||||
### trimEnd(self: string, trimChars: string = " \t\n\r"): string
|
||||
|
||||
This function is identical to `trim(self, trimChars)`, except it is only applied to the end of the first argument.
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Types
|
||||
|
||||
The type system in toy is opt-in, but allows a lot of robust checks at runtime when needed. Types themselves are first-class citizens. To retreive the type of an existing variable, use the `typeof` keyword.
|
||||
The type system in Toy is opt-in, but allows a lot of robust checks at runtime when needed. Types themselves are first-class citizens. To retrieve the type of an existing variable, use the `typeof` keyword.
|
||||
|
||||
```
|
||||
print typeof value;
|
||||
@@ -59,7 +59,7 @@ Const-ness, or the ability to fix the value of a variable, is part of the type s
|
||||
var ANSWER: int const = 42; //answer will never change
|
||||
```
|
||||
|
||||
You can also set the members of an array or dicitonary as const, or the entire compound:
|
||||
You can also set the members of an array or dictionary as const, or the entire compound:
|
||||
|
||||
```
|
||||
var members: [int const] = [1, 2, 3]; //1, 2 and 3 cannot be changed, but "members" can be modified or re-assigned
|
||||
@@ -69,7 +69,7 @@ var everything: [int] const = [4, 5, 6]; //everything is now const
|
||||
|
||||
## Astype
|
||||
|
||||
Due to the syntax of Toy, when storing a complex type into a varable, you may need to use the `astype` keyword to differentiate the value from an array or dictionary.
|
||||
Due to the syntax of Toy, when storing a complex type into a variable, you may need to use the `astype` keyword to differentiate the value from an array or dictionary.
|
||||
|
||||
```
|
||||
var t: type = astype [int]; //t is a type, representing an array of integers
|
||||
@@ -78,7 +78,7 @@ var u: type = [int]; //Error! it tried to assign an array with the sole entry "i
|
||||
|
||||
## First-Class Citizens
|
||||
|
||||
Types are first-class citizens. What this means is that they can be used just like any other value, as well as being stored in variables, and even returned from functions.
|
||||
Types are first-class citizens. What this means is that they can be used just like any other value, as well as being stored in variables and even returning from functions.
|
||||
|
||||
```
|
||||
fn decide(question) {
|
||||
@@ -97,7 +97,7 @@ var number: t = 0; //what if it had been false?
|
||||
|
||||
## Opaque Data
|
||||
|
||||
Sometimes, you may need to pass data through Toy that Toy can't normally handle. This data is called "opaque" data, and is passed around by reference rather than value. Anything can be passed in as opaque data, as long as it's represented as a void pointer in C.
|
||||
Sometimes, you may need to pass data through Toy that Toy can't normally handle. This data is called "opaque" data and is passed around by reference rather than value. Anything can be passed in as opaque data as long as it's represented as a void pointer in C.
|
||||
|
||||
```c
|
||||
Toy_Literal opaque = TOY_TO_OPAQUE_LITERAL(&data, 0);
|
||||
|
||||
Reference in New Issue
Block a user