Skip to content

Commit ee945ea

Browse files
committed
Updated: Documentation!
1 parent 96bbe26 commit ee945ea

4 files changed

Lines changed: 27 additions & 7 deletions

File tree

interpreter/examples/libraries.sk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mylib.fibonacci(10)
1212
time.sleep(1)
1313

1414
print("Pi: " + str(math.PI)) // PI from the math lib inside the simplelib library
15-
print("Now: " + str(time.formatTime(time.now())))
15+
print("Now: " + str(time.format(time.now())))
1616

17-
let elapsed = time.stopTimer(timer)
17+
let elapsed = time.stopTimer(0)
1818
print("Test file took " + str(elapsed) + " seconds to run!")

interpreter/src/libs/time.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static TIMER_COUNTER: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU6
1515

1616
pub fn register(env: &mut Environment) {
1717
env.define("now".into(), Value::NativeFn(now));
18-
env.define("formatTime".into(), Value::NativeFn(format_time));
18+
env.define("format".into(), Value::NativeFn(format));
1919
env.define("sleep".into(), Value::NativeFn(sleep));
2020

2121
env.define("startTimer".into(), Value::NativeFn(start_timer));
@@ -37,15 +37,15 @@ pub fn now(_args: Vec<Value>, span: TokenSpan, _: &mut Evaluator) -> Result<Valu
3737
}
3838
}
3939

40-
pub fn format_time(args: Vec<Value>, span: TokenSpan, _: &mut Evaluator) -> Result<Value, Error> {
40+
pub fn format(args: Vec<Value>, span: TokenSpan, _: &mut Evaluator) -> Result<Value, Error> {
4141
use chrono::{DateTime, Utc};
4242
// YYYY-MM-DD: HH:MM:SS
4343
match args.first() {
4444
Some(Value::Number(n)) => {
4545
let dt = DateTime::<Utc>::from(UNIX_EPOCH + std::time::Duration::from_secs_f64(*n));
4646
Ok(Value::String(dt.format("%Y-%m-%d: %H:%M:%S").to_string()))
4747
}
48-
_ => Err(err(span, "formatTime() expects 1 number".to_string())),
48+
_ => Err(err(span, "format() expects 1 number".to_string())),
4949
}
5050
}
5151

website/docs/Imports/libraries.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
Currently SK includes these built-in libraries
66

77
* The ```Math``` Library: See Imports/Math
8+
* The ```Time``` Library: See Imports/Time
89

910
> More will be possibly added in the future
1011
1112
### TODO:
1213

13-
* ```os```
14-
* ```files```
14+
* ```fs```
1515
* ```rand```
1616
* ```server*```

website/docs/Imports/time.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time
2+
3+
## The ```time``` library
4+
5+
```rs
6+
import time
7+
```
8+
9+
Basic time library that includes some simple debugging functions too!
10+
11+
* ```time.now()```, returns the current time in seconds from UNIX epoch
12+
* ```time.format()```, converts any timestamp from UNIX to ```YYYY-MM-DD: HH:MM:SS```
13+
* ```time.sleep```, freezes the thread for the given amount of seconds, if an interval is given, it will use the interval's midpoint
14+
15+
### Timer
16+
17+
The time library includes a timer! This creates a new thread that counts the time in seconds till the timer is stopped or the program is terminated.
18+
19+
* ```time.startTimer()``` returns the timer ID, starting from 0
20+
* ```time.stopTimer(ID)``` returns the timer elapsed time since start in seconds, requieres the timer's id

0 commit comments

Comments
 (0)