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
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
parent91c64b28853c318d7b5700dbcaf1feed30a0471a (diff)
Work under windows
-rw-r--r--CMakeLists.txt3
-rw-r--r--sys-1.0-0.rockspec2
-rw-r--r--sys-1.1-0.rockspec2
-rw-r--r--sys.c31
4 files changed, 30 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 029fd0f..e4a6db3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,3 +9,6 @@ SET(luasrc init.lua)
ADD_TORCH_PACKAGE(sys "${src}" "${luasrc}")
TARGET_LINK_LIBRARIES(sys luaT TH)
+IF(LUALIB)
+ TARGET_LINK_LIBRARIES(sys ${LUALIB})
+ENDIF()
diff --git a/sys-1.0-0.rockspec b/sys-1.0-0.rockspec
index bc34425..6054ae1 100644
--- a/sys-1.0-0.rockspec
+++ b/sys-1.0-0.rockspec
@@ -21,6 +21,6 @@ dependencies = {
build = {
type = "command",
- build_command = [[cmake -E make_directory build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$(LUA_BINDIR)/.." -DCMAKE_INSTALL_PREFIX="$(PREFIX)" && $(MAKE)]],
+ build_command = [[mkdir && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$(LUA_BINDIR)/.." -DCMAKE_INSTALL_PREFIX="$(PREFIX)" && $(MAKE)]],
install_command = "cd build && $(MAKE) install"
}
diff --git a/sys-1.1-0.rockspec b/sys-1.1-0.rockspec
index dd46ca2..22f5452 100644
--- a/sys-1.1-0.rockspec
+++ b/sys-1.1-0.rockspec
@@ -21,6 +21,6 @@ dependencies = {
build = {
type = "command",
- build_command = [[cmake -E make_directory build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$(LUA_BINDIR)/.." -DCMAKE_INSTALL_PREFIX="$(PREFIX)" && $(MAKE)]],
+ build_command = [[cmake -E make_directory build && cd build && cmake .. -DLUALIB=$(LUALIB) -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$(LUA_BINDIR)/.." -DCMAKE_INSTALL_PREFIX="$(PREFIX)" && $(MAKE)]],
install_command = "cd build && $(MAKE) install"
}
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