Skip to content

Commit

Permalink
Add example for time api
Browse files Browse the repository at this point in the history
  • Loading branch information
Spydr06 committed Oct 28, 2022
1 parent 81ef30b commit b5d88e5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
![](examples/assets/img/random.png)
</details>

<details>
<summary><b>Time & Timer API</b></summary>

### [time.csp](examples/std/time.csp)
![](examples/assets/img/time.png)
</details>

> More examples can be found in the [**examples**](./examples/) directory
## Current State
Expand Down
Binary file added examples/assets/img/time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions examples/std/read_file.csp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import "file.csp";
import "io.csp";

macro PATH { "examples/assets/test.txt" }

fn main(): i32 {
using std;

with f = file::open(PATH!, file::READ) {
let path = "examples/assets/test.txt";

with f = file::open(path, file::READ) {
let buffer = file::read_all(f);
io::puts(buffer);
string::free(buffer);
}
else
io::eprintf("%E `" PATH! "`\n");
io::eprintf("%E `%s`\n", path);

<- 0;
}
9 changes: 5 additions & 4 deletions examples/std/time.csp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# time.csp
import "std.csp";

fn main(): i32 {
using std;
let t = time::get();

std::timer::do_each(1000, || => {
with time_str = fmt::time("%D.%M.%Y %h:%m:%s", t) {
timer::do_each(1000, || => {
with time_str = fmt::time("%D.%M.%Y %h:%m:%s", time::get()) {
io::puts(time_str);
}
});

<- 0;
}
}

2 changes: 1 addition & 1 deletion src/std/directory.csp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace std {
using io;

let fd = 0;
if (fd = syscall::open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0) < 0)
if fd = syscall::open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0) < 0
{
error::new(std::Errno::IO, "could not open directory");
<- nil;
Expand Down
2 changes: 1 addition & 1 deletion src/std/testing.csp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace std {

fn assert_fatal(t: &Testing, condition: bool, error_msg: &const char, args: ...) {
do {
error::new(Errno::NILPTR, "argument t is nil");
error::new(std::Errno::NILPTR, "argument t is nil");
ret;
} unless t && t.tests;

Expand Down

0 comments on commit b5d88e5

Please sign in to comment.