9 #include "common/err.h"
11 UwUVMValue uwu_exit(UwUVMArgs *args)
13 uwuutil_require_max("os.exit", args, 1);
18 exit_code = uwuint_get(uwuvm_get_arg(args, 0));
21 return uwunil_create();
24 UwUVMValue uwu_sleep(UwUVMArgs *args)
26 uwuutil_require_exact("os.sleep", args, 1);
28 UwUVMValue value = uwuvm_get_arg(args, 0);
30 if (value.type != &uwuint_type)
31 error("type error: os.sleep requires an integer as $1\n");
33 long millis = uwuint_get(value);
36 error("type error: os.sleep requires a positive value as $2\n");
38 struct timespec ts = {
39 .tv_sec = millis / 1000,
40 .tv_nsec = 1000000 * (millis % 1000),
43 while (nanosleep(&ts, &ts) != 0)
45 syserror("nanosleep", NULL);
47 return uwunil_create();
50 UwUVMValue uwu_execute(UwUVMArgs *args)
52 uwuutil_require_exact("os.execute", args, 1);
54 char *command = uwustr_get(uwuvm_get_arg(args, 0));
55 int ret = system(command);
58 return uwuint_create(ret);
61 UwUVMValue uwu_time(UwUVMArgs *args)
63 uwuutil_require_exact("os.time", args, 0);
66 clock_gettime(CLOCK_REALTIME, &ts);
68 return uwuint_create(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);