From b4c18cac125fc8610e0b52bdab0bb63ff9a7fbdb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 12 Nov 2022 22:44:24 +1100 Subject: [PATCH] Added timer library docs --- README.md | 2 +- standard-library.md | 2 +- timer-library.md | 46 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 timer-library.md diff --git a/README.md b/README.md index b726008..bbb2b88 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ print tally(); //3 * [Quick Start Guide](quick-start-guide) * [Types](types) * [Standard Library](standard-library) -* ~~Timer Library~~ Under Development +* [Timer Library](timer-library) * [Game Engine](game-engine) # Deep Dive diff --git a/standard-library.md b/standard-library.md index 99d9ab9..34b9bcb 100644 --- a/standard-library.md +++ b/standard-library.md @@ -8,7 +8,7 @@ The standard library can usually be accessed with the `import` keyword: import standard; ``` -## Clock() +## fn clock(): string This function returns the current timestamp. diff --git a/timer-library.md b/timer-library.md new file mode 100644 index 0000000..aa4d65f --- /dev/null +++ b/timer-library.md @@ -0,0 +1,46 @@ +# Timer Library + +The timer library offers a series of utility functions for generating and manipulating timers, which can be used for recording or initiating timed events. Please be aware that "timers" are opaque objects, which must be destroyed when you're done with them, otherwise you'll have a memory leak in your program. + +These functions are implemented by the host program, so they may not all be provided by default. + +The timer library can usually be accessed with the `import` keyword: + +``` +import timer; +``` + +## fn startTimer(): opaque + +This function returns an `opaque` timer object, representing the point in time when the function was called. + +## fn _stopTimer(self: opaque): opaque + +This function returns an `opaque` timer object, representing the duration between when the `self` argument was created, and when this function was called. + +## fn createTimer(seconds: int, microseconds: int): opaque + +This function returns an `opaque` timer object, with seconds and microseconds set to the given values. To give a negative value between 0 and -1, give a negative value for microseconds (negative 0 is not a thing in Toy). + +Please note that `microseconds` has upper and lower bounds of -1,000,000 to 1,000,000. Also, if seconds has a non-zero value, then microseconds has a lower bounds of 0 instead. + +## fn _getTimerSeconds(self: opaque): int + +This function returns an integer value, representing the seconds value of the timer object. + +## fn _getTimerMicroseconds(self: opaque): int + +This function returns an integer value, representing the seconds value of the timer object. + +## fn _compareTimer(self: opaque, other: opaque): opaque + +This function returns an `opaque` timer object, representing the duration between the `self` and `other` arguments. The return value may be negative. + +## fn _timerToString(self: opaque): string + +This function returns a string representation of the `self` argument, which can be casted into other basic [types](types). + +## fn _destroyTimer(self: opaque): null + +This function cleans up the memory of the `self` timer object. +