lua: test.lua:2: module 'socket' not found:
no field package.preload['socket']
no file '/usr/local/share/lua/5.2/socket.lua'
no file '/usr/local/share/lua/5.2/socket/init.lua'
no file '/usr/local/lib/lua/5.2/socket.lua'
no file '/usr/local/lib/lua/5.2/socket/init.lua'
no file '/usr/share/lua/5.2/socket.lua'
no file '/usr/share/lua/5.2/socket/init.lua'
no file './socket.lua'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/socket.so'
no file '/usr/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'
stack traceback:
[C]: in function 'require'
test.lua:2: in main chunk
系统明明有socket.lua,但就是不行,怎么办呢?
有2个办法
其中一个办法是在lua里面设置:
package.path = package.path .. ";/usr/share/lua/5.2/?.lua"
package.cpath = package.cpath .. ";/usr/lib64/lua/5.2/?.so"
另外一个办法是在系统里面设置:
export LUA_PATH=/usr/share/lua/5.2/?.ua
export LUA_CPATH=/usr/lib64/lua/5.2/?.so
参考资料: