123456789101112131415161718192021222324252627282930313233343536 |
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include "libraries/Time.h"
- #include "utils/Functions.h"
- static void lTimeGetMillis(Script* sc) {
- struct timespec time;
- if(clock_gettime(CLOCK_REALTIME, &time)) {
- sError(sc, "cannot get clock time: %s", strerror(errno));
- return;
- }
- sPushInt64(sc, time.tv_nsec / 1000000L + time.tv_sec * 1000L);
- }
- static void lTimeGetNanos(Script* sc) {
- struct timespec time;
- if(clock_gettime(CLOCK_BOOTTIME, &time)) {
- sError(sc, "cannot get clock time: %s", strerror(errno));
- return;
- }
- sPushInt64(sc, time.tv_nsec + time.tv_sec * 1000000000L);
- }
- void lTimeRegister() {
- Structs sts;
- stsInit(&sts);
- Function f;
- gfInit(&f, "getMillis", dtInt64(), lTimeGetMillis);
- gfsAdd(&f);
- gfInit(&f, "getNanos", dtInt64(), lTimeGetNanos);
- gfsAdd(&f);
- }
|