In this post, I would demonstrate how to solve the following error when using mobdebug with lua:
/usr/local/bin/lua: ./mobdebug.lua:99: module 'socket' not found:
2. The solution
2.1 What is
MobDebug is a remote debugger for Lua .
mobdebug is a pure lua-implemented remote debugger, which relies on luasocket. The basic communication method is to use strings to transmit the corresponding control instructions and execution results between the target program and the IDE (should be compatible with Telnet, directly Telnet to After mobdebug opens the port, you can use the command line to debug Lua. The data that mobdebug interacts with the remote is directly packaged into a string in Lua format. This place uses a serialization reverser implemented by Lua. The serialization open source library https://github.com/pkulchenko/serpent, the principle is also to intervene in the execution of Lua by setting the debug hook function of lua itself, and use the lua debug library to obtain the required information and send it to the remote end. Just as the following picture shows:
And the communication mode used by mobdebug is responsive, e.g. most of the time, after the remote IDE sends a command to the debug target program, it enters the state of waiting for the debug target to return the result. A Command queue is created. If the Command needs to be answered, the remaining Commands in the queue will only be sent after the current Command is processed.
2.2 How to enable mobdebug with lua?
If you want to do local lua debugging, just do as follows:
And then debug the lua application :
2.3 The error I encountered when using mobdebug with lua
When I debug the lua application with mobdebug, I got this error:
Start mobdebug server at port:8172 Waiting for process connection... /usr/local/bin/lua: ./mobdebug.lua:99: module 'socket' not found: no field package.preload['socket'] no file '/usr/local/share/lua/5.4/socket.lua' no file '/usr/local/share/lua/5.4/socket/init.lua' no file '/usr/local/lib/lua/5.4/socket.lua' no file '/usr/local/lib/lua/5.4/socket/init.lua' no file './socket.lua' no file './socket/init.lua' no file '/Users/bswen/Library/Application Support/IntelliJIdea2019.3/intellij-emmylua/classes/debugger/mobdebug/socket.lua' no file '/Users/bswen/lua-projects/openresty-demo/src/socket.lua' no file '/Users/bswen/lua-projects/hello-module/src/socket.lua' no file '' no file '/usr/local/lib/lua/5.4/socket.so' no file '/usr/local/lib/lua/5.4/loadall.so' no file './socket.so' stack traceback: [C]: in function 'require' ./mobdebug.lua:99: in main chunk [C]: in function 'require' (command line):1: in main chunk [C]: in ?
2.4 How to solve this error?
You can do this to solve this error:
sudo luarocks install luasocket
LuaRocks is the package manager for Lua modules. It allows you to create and install Lua modules as self-contained packages called rocks.
In this post, I demonstrated how to solve the
module not found error when using lua with mobdebug. That’s it, thanks for your reading.