mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
...
This commit is contained in:
parent
fcbe56b5a9
commit
6ee43311ea
@ -6,3 +6,7 @@ label: time
|
||||
### `time.time()`
|
||||
|
||||
Returns the current time in seconds since the epoch as a floating point number.
|
||||
|
||||
### `time.sleep(secs)`
|
||||
|
||||
Suspend execution of the calling thread for the given number of seconds.
|
@ -797,6 +797,17 @@ inline void add_module_time(VM* vm){
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
return VAR(std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() / 1000000.0);
|
||||
});
|
||||
|
||||
vm->bind_func<1>(mod, "sleep", [](VM* vm, ArgsView args) {
|
||||
f64 seconds = FLOAT(args[0]);
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
while(true){
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
f64 elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now - begin).count() / 1000000.0;
|
||||
if(elapsed >= seconds) break;
|
||||
}
|
||||
return vm->None;
|
||||
});
|
||||
}
|
||||
|
||||
inline void add_module_sys(VM* vm){
|
||||
|
Loading…
x
Reference in New Issue
Block a user