#include #include #include #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); }