LuaHelper icon indicating copy to clipboard operation
LuaHelper copied to clipboard

LuaSocket doesn't work out of the box (workaround inside)

Open MarioRicalde opened this issue 1 year ago • 1 comments

Issue

When installing the extension, debugging does not work out of the box due to the following error:

[LuaPanda] [Error] reGetSock fail
[LuaPanda] [Error] Start debugger but get Socket fail , please install luasocket!

Execution is fine since it uses the included Lua binary. I wasn't able to get the included DLLs to work so I ended up having to compile them. I have made a small tutorial to work around the issue when using Windows 11:


Workaround

Download the Lua (5.4) Interpreter an put it somewhere to use it, in my case /C/Users/MarioRicalde/OneDrive/Documents/Lua/

Install MSYS2 https://www.msys2.org/#installation

In the MSYS terminal and install the toolchain:

pacman -S mingw-w64-x86_64-toolchain

Download latest release (src) or clone from https://github.com/lunarmodules/luasocket/releases.

Using Msys2 mingw64 and navigate to directory, adjust the paths to match your configuration (hint, replace C/Users/MarioRicalde/OneDrive/Documents with your path ):

x86_64-w64-mingw32-gcc -O2 -c -o src/luasocket.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/luasocket.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/timeout.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/timeout.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/buffer.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/buffer.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/io.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/io.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/auxiliar.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/auxiliar.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/options.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/options.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/inet.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/inet.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/except.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/except.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/select.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/select.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/tcp.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/tcp.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/udp.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/udp.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/compat.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/compat.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/wsocket.o -I/C/Users/MarioRicalde/OneDrive/Documents/Lua/include/lua/5.4 src/wsocket.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -I/c/windows/system32/include
mkdir socket
x86_64-w64-mingw32-gcc  -shared -o socket/core.dll src/luasocket.o src/timeout.o src/buffer.o src/io.o src/auxiliar.o src/options.o src/inet.o src/except.o src/select.o src/tcp.o src/udp.o src/compat.o src/wsocket.o -lws2_32 /C/Users/MarioRicalde/OneDrive/Documents/Lua/lua54.dll -lm

With that you should have the core.dll file:

MarioRicalde@MR-WS MINGW64 /c/Users/MarioRicalde/OneDrive/Documents/Lua/other/luasocket-3.1.0
$ ls socket
core.dll

Go to VSCode, Ctrl + P, write:

LuaHelper: Open Debug Folder

That will open explorer, go into luasocket > win > x64 > lua5.4 > socket

Rename core.dll to core.bak.dll and add your newly compiled core.dll

Everything should work now 🎊

MarioRicalde avatar Jul 24 '24 00:07 MarioRicalde

very good, I use your way successfully solve my question, I find the same error in mac, could you provide another way to solve it. thank you, looking forward to your replay.

zflbigbang avatar Oct 17 '24 14:10 zflbigbang