Reputation: 5069
Run the following simple lua script but got error. I am running lua 5.2 on ubuntu.
local host, port = "127.0.0.1", 80
local socket = require("socket")
local tcp = assert(socket.tcp())
tcp:connect(host, port);
--note the newline below
tcp:send("GET / HTTP/1.1\r\n\r\n");
Here is the error:
~/learn/lua$ lua te.lua
lua: te.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'
te.lua:2: in main chunk
[C]: in ?
Upvotes: 0
Views: 330
Reputation: 5069
Problem solved after installing the package manager luarocks and then socket package.
Here are the commands from the page
$ wget https://luarocks.org/releases/luarocks-2.4.1.tar.gz
$ tar zxpf luarocks-2.4.1.tar.gz
$ cd luarocks-2.4.1
$ ./configure; sudo make bootstrap
$ sudo luarocks install luasocket
$ lua
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> require "socket"
Upvotes: 1