ref: ddfbe7c4de63f8a47d69974e1b6262cc78f7bb16
parent: 54d451808fafb72fdc70df17f4b811968b04bbbd
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Oct 31 23:37:47 EDT 2024
add "sleep" builtin
--- a/builtins.c
+++ b/builtins.c
@@ -301,7 +301,7 @@
return mk_double(sec_realtime());
}
-static double
+double
todouble(value_t a)
{
if(isfixnum(a))
--- a/flisp.c
+++ b/flisp.c
@@ -13,6 +13,7 @@
#include "types.h"
#include "print.h"
#include "read.h"
+#include "timefuncs.h"
#include "equal.h"
#include "hashing.h"
#include "table.h"
@@ -2068,6 +2069,15 @@
fl_free_gc_handles(2);
}
return first;
+}
+
+BUILTIN("sleep", fl_sleep)
+{
+ if(nargs > 1)
+ argcount(nargs, 1);
+ double s = nargs > 0 ? todouble(args[0]) : 0;
+ sleep_ms(s * 1000.0);
+ return FL_T;
}
static const builtinspec_t builtin_fns[] = {