summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2012-10-30 13:14:57 -0700
committerSam Roberts <vieuxtech@gmail.com>2012-10-30 13:14:57 -0700
commitc24f52acbfa05a785fdd1c0a68b043b9af8ed124 (patch)
tree73828d93ebd0c7f120b3cd3c4ebe85a9389366a6
parentb7bbcd557cb901e16f41f89a889627b96ecbdb59 (diff)
downloadlibnet-c24f52acbfa05a785fdd1c0a68b043b9af8ed124.tar.gz
Build lua binding on win32.
-rw-r--r--.gitignore4
-rw-r--r--lua/msvcbuild.bat20
-rw-r--r--lua/net.c10
3 files changed, 34 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 73d2906..dd31b2e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,12 @@
*.a
+*.dll
+*.exp
*.la
+*.lib
*.lo
*.loT
*.o
+*.obj
*.out.dSYM
*.so.dSYM
*~
diff --git a/lua/msvcbuild.bat b/lua/msvcbuild.bat
new file mode 100644
index 0000000..b03ba07
--- /dev/null
+++ b/lua/msvcbuild.bat
@@ -0,0 +1,20 @@
+@rem Script to build Lua under "Visual Studio .NET Command Prompt".
+@rem Dependencies are:
+@rem Lua
+@rem winpcap, specifically, the winpcap developer pack
+@rem dnet, Dug Song's net library, aka libdumbnet
+
+@setlocal
+@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
+@set MYLINK=link /nologo
+@set MYMT=mt /nologo
+
+@set LUA=..\..\lua-5.1\src
+@set WINPCAP=..\..\WpdPack
+@set DNET=..\..\libdnet-1.11-win32
+
+%MYCOMPILE% /I..\libnet\include\win32 /I..\libnet\include /I%LUA% /I%WINPCAP%\Include /I%DNET%\include *.c
+%MYLINK% /DLL /libpath:%WINPCAP%\Lib /out:net.dll *.obj %LUA%\lua51.lib ..\libnet\win32\Debug\Libnet.lib %DNET%\lib\dnet.lib
+if exist net.dll.manifest^
+ %MYMT% -manifest net.dll.manifest -outputresource:net.dll;2
+
diff --git a/lua/net.c b/lua/net.c
index 48759ec..c009122 100644
--- a/lua/net.c
+++ b/lua/net.c
@@ -36,6 +36,9 @@ THE POSSIBILITY OF SUCH DAMAGE.
#include "libnet_decode.h"
#include <libnet.h>
+
+#define LUA_BUILD_AS_DLL /* To pull in LUA_API definitions for modules */
+
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
@@ -1294,6 +1297,8 @@ static int lnet_chksum(lua_State *L)
return 1;
}
+#ifndef _WIN32
+/* TODO see http://stackoverflow.com/questions/7827062/is-there-a-windows-equivalent-of-nanosleep */
/*-
-- remaining = net.nanosleep(seconds)
@@ -1324,6 +1329,7 @@ static int lnet_nanosleep(lua_State *L)
}
}
+/* TODO use GetSystemTime or GetSystemTimeAsFileTime */
/*-
t = net.gettimeofday()
@@ -1343,6 +1349,8 @@ static int lnet_gettimeofday(lua_State *L)
}
}
+#endif
+
/*-
-- net.init(injection, device)
@@ -1415,8 +1423,10 @@ static const luaL_reg net[] =
{"pton", lnet_pton},
{"htons", lnet_htons},
{"checksum", lnet_chksum},
+#ifndef _WIN32
{"nanosleep", lnet_nanosleep},
{"gettimeofday", lnet_gettimeofday},
+#endif
{"init", lnet_init},
{NULL, NULL}
};