From 405881f2d7de67696903f1d6d490a6f02236d259 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Thu, 9 Apr 2020 19:45:00 -0500 Subject: [PATCH] LuaSocket now working on Windows. --- singe/buildRelease.sh | 14 +++++----- singe/singe.c | 30 +++++++++++++++------ singe/thirdparty/luasocket/src/serial.c | 2 ++ singe/thirdparty/luasocket/src/unix.c | 2 ++ singe/thirdparty/luasocket/src/unixdgram.c | 2 ++ singe/thirdparty/luasocket/src/unixstream.c | 2 ++ 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/singe/buildRelease.sh b/singe/buildRelease.sh index 53bd5025b..2b07b90e0 100755 --- a/singe/buildRelease.sh +++ b/singe/buildRelease.sh @@ -63,9 +63,9 @@ function doBuild() { # The grep nonsense hides a warning we don't care about. ${CROSS}-${CPPCOMPILER} -o "${TARGET}" ${OFILES} ${EXTRA_OFILES} "-L${SOURCE_DIR}/../thirdparty-build/${OSNAME}/${OSARCH}/installed/lib" ${EXTRA_LD_FLAGS} 2>&1 | grep -v loslib || true - echo "Compressing ${TARGET}..." - ${CROSS}-strip "${TARGET}" - upx -9 "${TARGET}" + #echo "Compressing ${TARGET}..." + #${CROSS}-strip "${TARGET}" + #upx -9 "${TARGET}" cd .. rm -rf temp @@ -103,9 +103,9 @@ echo -e "${G_L}\nWindows i686\n${G_L}" CROSS="i686-w64-mingw32" CCOMPILER="gcc" CPPCOMPILER="g++" -EXTRA_CFLAGS="-O2" +EXTRA_CFLAGS="-O2 -DLUASOCKET_INET_PTON" EXTRA_OFILES="/tmp/singe.res" -EXTRA_LD_FLAGS="-mwindows -static -lmingw32 -l:everything.a -lm -lbcrypt -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid -Dmain=SDL_main" +EXTRA_LD_FLAGS="-mwindows -static -lmingw32 -l:everything.a -lm -lbcrypt -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid -lws2_32 -Dmain=SDL_main" xcf2png icon.xcf -o /tmp/icon.png icotool -c -o /tmp/icon.ico /tmp/icon.png ${CROSS}-windres singe.rc -O coff -o /tmp/singe.res @@ -119,9 +119,9 @@ echo -e "${G_L}\nWindows x86_64\n${G_L}" CROSS="x86_64-w64-mingw32" CCOMPILER="gcc" CPPCOMPILER="g++" -EXTRA_CFLAGS="-O2" +EXTRA_CFLAGS="-O2 -DLUASOCKET_INET_PTON" EXTRA_OFILES="/tmp/singe.res" -EXTRA_LD_FLAGS="-mwindows -static -lmingw32 -l:everything.a -lm -lbcrypt -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid -Dmain=SDL_main" +EXTRA_LD_FLAGS="-mwindows -static -lmingw32 -l:everything.a -lm -lbcrypt -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid -lws2_32 -Dmain=SDL_main" xcf2png icon.xcf -o /tmp/icon.png icotool -c -o /tmp/icon.ico /tmp/icon.png ${CROSS}-windres singe.rc -O coff -o /tmp/singe.res diff --git a/singe/singe.c b/singe/singe.c index a23c48ce4..95500bd72 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -34,6 +34,12 @@ #include "thirdparty/manymouse/manymouse.h" #include "thirdparty/luafilesystem/src/lfs.h" #include "thirdparty/luasocket/src/luasocket.h" +#ifndef _WIN32 +#include "thirdparty/luasocket/src/unixdgram.h" +#include "thirdparty/luasocket/src/unixstream.h" +// There is no serial.h, so fake it. +LUASOCKET_API int luaopen_socket_serial(lua_State *L); +#endif #include "main.h" #include "util.h" @@ -338,6 +344,7 @@ void luaTrace(lua_State *L, char *method, char *fmt, ...); void processKey(bool down, int keysym, int32_t scancode); void putPixel(int32_t x, int32_t y); void startControllers(void); +void startLuaContext(lua_State *L); void stopControllers(void); void takeScreenshot(void); void updatePauseState(void); @@ -3408,10 +3415,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) { // Load controller mappings _global.luaContext = luaL_newstate(); - luaL_openlibs(_global.luaContext); - lua_atpanic(_global.luaContext, luaError); - luaopen_lfs(_global.luaContext); - luaopen_socket_core(_global.luaContext); + startLuaContext(_global.luaContext); // Load framework if (luaL_loadbuffer(_global.luaContext, (char *)Framework_singe, Framework_singe_len, "Input Mappings") || lua_pcall(_global.luaContext, 0, 0, 0)) utilDie("%s", lua_tostring(_global.luaContext, -1)); // Load default mappings @@ -3489,10 +3493,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) { // Start Lua for game _global.luaContext = luaL_newstate(); - luaL_openlibs(_global.luaContext); - lua_atpanic(_global.luaContext, luaError); - luaopen_lfs(_global.luaContext); - luaopen_socket_core(_global.luaContext); + startLuaContext(_global.luaContext); // Lua API for Singe lua_register(_global.luaContext, "colorBackground", apiColorBackground); @@ -4138,6 +4139,19 @@ void startControllers(void) { } +void startLuaContext(lua_State *L) { + luaL_openlibs(L); + lua_atpanic(L, luaError); + luaopen_lfs(L); + luaopen_socket_core(L); +#ifndef _WIN32 + unixdgram_open(L); + unixstream_open(L); + luaopen_socket_serial(L); +#endif +} + + void stopControllers(void) { int32_t x; diff --git a/singe/thirdparty/luasocket/src/serial.c b/singe/thirdparty/luasocket/src/serial.c index 21485d3e2..1aced0d89 100644 --- a/singe/thirdparty/luasocket/src/serial.c +++ b/singe/thirdparty/luasocket/src/serial.c @@ -1,3 +1,4 @@ +#ifndef _WIN32 /*=========================================================================*\ * Serial stream * LuaSocket toolkit @@ -169,3 +170,4 @@ static int global_create(lua_State *L) { buffer_init(&un->buf, &un->io, &un->tm); return 1; } +#endif diff --git a/singe/thirdparty/luasocket/src/unix.c b/singe/thirdparty/luasocket/src/unix.c index 268d8b212..b6574a5aa 100644 --- a/singe/thirdparty/luasocket/src/unix.c +++ b/singe/thirdparty/luasocket/src/unix.c @@ -1,3 +1,4 @@ +#ifndef _WIN32 /*=========================================================================*\ * Unix domain socket * LuaSocket toolkit @@ -67,3 +68,4 @@ LUASOCKET_API int luaopen_socket_unix(lua_State *L) return 1; } +#endif diff --git a/singe/thirdparty/luasocket/src/unixdgram.c b/singe/thirdparty/luasocket/src/unixdgram.c index 3ac3c5e02..f58af2a00 100644 --- a/singe/thirdparty/luasocket/src/unixdgram.c +++ b/singe/thirdparty/luasocket/src/unixdgram.c @@ -1,3 +1,4 @@ +#ifndef _WIN32 /*=========================================================================*\ * Unix domain socket dgram submodule * LuaSocket toolkit @@ -403,3 +404,4 @@ static int global_create(lua_State *L) return 2; } } +#endif diff --git a/singe/thirdparty/luasocket/src/unixstream.c b/singe/thirdparty/luasocket/src/unixstream.c index 02aced9c8..b9868ec7e 100644 --- a/singe/thirdparty/luasocket/src/unixstream.c +++ b/singe/thirdparty/luasocket/src/unixstream.c @@ -1,3 +1,4 @@ +#ifndef _WIN32 /*=========================================================================*\ * Unix domain socket stream sub module * LuaSocket toolkit @@ -353,3 +354,4 @@ static int global_create(lua_State *L) { return 2; } } +#endif