aboutsummaryrefslogtreecommitdiff
path: root/crates/sloth_vm/src/sloth_std/time.rs
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-05-24 00:23:13 -0500
committerCody <cody@codyq.dev>2023-05-24 00:23:13 -0500
commit9c41dd96cd3652ce9c46307184e8055704655338 (patch)
tree07071d74da7398593fc5b9cfe5c4df0229ee4eb0 /crates/sloth_vm/src/sloth_std/time.rs
parent2418d68631f6e338251f2d988de2d3fde206982b (diff)
parentdf00e9ff2c2b563c79beb71ba8c510233b04f3bf (diff)
downloadsloth-9c41dd96cd3652ce9c46307184e8055704655338.tar.gz
Merge branch 'master' into compiler
Diffstat (limited to 'crates/sloth_vm/src/sloth_std/time.rs')
-rw-r--r--crates/sloth_vm/src/sloth_std/time.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/sloth_vm/src/sloth_std/time.rs b/crates/sloth_vm/src/sloth_std/time.rs
new file mode 100644
index 0000000..b27e0b5
--- /dev/null
+++ b/crates/sloth_vm/src/sloth_std/time.rs
@@ -0,0 +1,29 @@
+use std::{thread, time};
+
+use crate::native::{self, NativeFunction, NativeFunctionResult};
+use crate::value::Primitive;
+use crate::value::Primitive::Integer;
+use crate::VM;
+
+fn wait(_vm: &mut VM, args: &[Primitive]) -> NativeFunctionResult {
+ let sec = args.get(0).cloned();
+
+ let Some(Integer(sec)) = sec else {
+ return Err(native::Error::InvalidArgument);
+ };
+
+ thread::sleep(time::Duration::from_secs(sec.try_into().unwrap()));
+
+ Ok(Primitive::Empty)
+}
+
+pub const WAIT: NativeFunction = NativeFunction {
+ name: "wait",
+ function: wait,
+ arity: 1,
+ returns_value: false,
+ doc: Some(
+ "NativeFunction wait: \n\targs: sec (int)\n\tdesc: Waits for <sec> seconds.\n\tExample: \
+ `wait(10); # Waits 10 seconds`",
+ ),
+};