Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/sys.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sys.c
diff options
context:
space:
mode:
authorsamehkhamis <sameh.khamis@gmail.com>2015-07-24 03:35:37 +0300
committersamehkhamis <sameh.khamis@gmail.com>2015-07-24 03:35:37 +0300
commit05b1de32917bda2aa9e2fc0e3379afefc962cb6a (patch)
treecf101567362f622d0f5f45f4305dd1da7f4ddedc /sys.c
parent91c64b28853c318d7b5700dbcaf1feed30a0471a (diff)
Work under windows
Diffstat (limited to 'sys.c')
-rw-r--r--sys.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/sys.c b/sys.c
index 489fdce..5425723 100644
--- a/sys.c
+++ b/sys.c
@@ -1,16 +1,30 @@
#include <lua.h>
#include <lauxlib.h>
-#ifdef LUA_WIN
+#ifdef _WIN32
+
+#define WINDOWS_LEAN_AND_MEAN
+#include <windows.h>
+#include <stdint.h>
static int l_clock(lua_State *L) {
- printf("warning: sys.clock not implemented on Windows\n");
- return 0;
+ static const uint64_t EPOCH = 116444736000000000ULL;
+ SYSTEMTIME systemtime;
+ FILETIME filetime;
+ uint64_t time;
+ GetSystemTime(&systemtime);
+ GetSystemTimeAsFileTime(&filetime);
+ time = (((uint64_t)filetime.dwHighDateTime) << 32) + ((uint64_t)filetime.dwLowDateTime);
+ double precise_time = (time - EPOCH) / 10000000.0;
+ lua_pushnumber(L, precise_time);
+ return 1;
}
static int l_usleep(lua_State *L) {
- printf("warning: sys.usleep not implemented on Windows\n");
- return 0;
+ int time = 1;
+ if (lua_isnumber(L, 1)) time = lua_tonumber(L, 1);
+ Sleep(time / 1000);
+ return 1;
}
#else
@@ -50,7 +64,12 @@ static const struct luaL_Reg routines [] = {
{NULL, NULL}
};
-int luaopen_libsys(lua_State *L)
+#if defined(_WIN32)
+ #define SYS_DLLEXPORT __declspec(dllexport) __cdecl
+#else
+ #define SYS_DLLEXPORT
+#endif
+int SYS_DLLEXPORT luaopen_libsys(lua_State *L)
{
lua_newtable(L);
#if LUA_VERSION_NUM == 501