LMMS
Loading...
Searching...
No Matches
eel_misc.h
Go to the documentation of this file.
1#ifndef _EEL_MISC_H_
2#define _EEL_MISC_H_
3
4
5#ifndef _WIN32
6#include <sys/time.h>
7#endif
8#include <time.h>
9// some generic EEL functions for things like time
10
11#ifndef EEL_MISC_NO_SLEEP
12static EEL_F NSEEL_CGEN_CALL _eel_sleep(void *opaque, EEL_F *amt)
13{
14 if (*amt >= 0.0)
15 {
16 #ifdef _WIN32
17 if (*amt > 30000000.0) Sleep(30000000);
18 else Sleep((DWORD)(*amt+0.5));
19 #else
20 if (*amt > 30000000.0) usleep(((useconds_t)30000000)*1000);
21 else usleep((useconds_t)(*amt*1000.0+0.5));
22 #endif
23 }
24 return 0.0;
25}
26#endif
27
28static EEL_F * NSEEL_CGEN_CALL _eel_time(void *opaque, EEL_F *v)
29{
30 *v = (EEL_F) time(NULL);
31 return v;
32}
33
34static EEL_F * NSEEL_CGEN_CALL _eel_time_precise(void *opaque, EEL_F *v)
35{
36#ifdef _WIN32
37 LARGE_INTEGER freq,now;
38 QueryPerformanceFrequency(&freq);
39 QueryPerformanceCounter(&now);
40 *v = (double)now.QuadPart / (double)freq.QuadPart;
41 // *v = (EEL_F)timeGetTime() * 0.001;
42#else
43#ifdef __cplusplus
44 struct timeval tm={};
45#else
46 struct timeval tm={0,};
47#endif
48 gettimeofday(&tm,NULL);
49 *v = tm.tv_sec + tm.tv_usec*0.000001;
50#endif
51 return v;
52}
53
54
56{
57#ifndef EEL_MISC_NO_SLEEP
59#endif
62}
63
64#ifdef EEL_WANT_DOCUMENTATION
65static const char *eel_misc_function_reference =
66#ifndef EEL_MISC_NO_SLEEP
67 "sleep\tms\tYields the CPU for the millisecond count specified, calling Sleep() on Windows or usleep() on other platforms.\0"
68#endif
69 "time\t[&val]\tSets the parameter (or a temporary buffer if omitted) to the number of seconds since January 1, 1970, and returns a reference to that value. "
70 "The granularity of the value returned is 1 second.\0"
71 "time_precise\t[&val]\tSets the parameter (or a temporary buffer if omitted) to a system-local timestamp in seconds, and returns a reference to that value. "
72 "The granularity of the value returned is system defined (but generally significantly smaller than one second).\0"
73;
74#endif
75
76
77#endif
#define NULL
Definition CarlaBridgeFormat.cpp:30
unsigned v[N_MAX]
Definition inflate.c:1584
#define NSEEL_addfunc_retptr(name, np, pproc, fptr)
Definition eel_import.h:55
#define NSEEL_addfunc_retval(name, np, pproc, fptr)
Definition eel_import.h:51
void *(* NSEEL_PProc_THIS)(void *data, int data_size, struct _compileContext *ctx)
Definition eel_import.h:40
void EEL_misc_register()
Definition eel_misc.h:55
static EEL_F *NSEEL_CGEN_CALL _eel_time_precise(void *opaque, EEL_F *v)
Definition eel_misc.h:34
static EEL_F NSEEL_CGEN_CALL _eel_sleep(void *opaque, EEL_F *amt)
Definition eel_misc.h:12
static EEL_F *NSEEL_CGEN_CALL _eel_time(void *opaque, EEL_F *v)
Definition eel_misc.h:28
#define opaque
Definition eelscript.h:281
JHUFF_TBL long freq[]
Definition jchuff.h:50
#define NSEEL_CGEN_CALL
Definition ns-eel.h:44
unsigned int DWORD
Definition swell-types.h:164
void Sleep(int ms)
Definition swell.cpp:63