From 19fefeb732d559195edb01ebc36170c0cf9a0308 Mon Sep 17 00:00:00 2001 From: nic-gaffney Date: Fri, 14 Apr 2023 04:57:53 -0500 Subject: eepy --- crates/sloth_vm/src/sloth_std/time.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 crates/sloth_vm/src/sloth_std/time.rs (limited to 'crates/sloth_vm/src/sloth_std/time.rs') 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..4df715e --- /dev/null +++ b/crates/sloth_vm/src/sloth_std/time.rs @@ -0,0 +1,25 @@ +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, +}; -- cgit v1.2.3