2016-11-12 2 views
0

Führen Sie das folgende einfache Lua-Skript, aber Fehler erhalten. Ich betreibe Lua 5.2 auf Ubuntu. HierFehler beim Laden des Moduls beim Ausführen eines einfachen Lua-Skripts als TCP-Client

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"); 

ist der Fehler:

~/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 ? 
+0

Mögliche Duplikat [Modulsockel nicht gefunden lua] (http://stackoverflow.com/questions/36975868/module-socket-not-found-lua) –

+0

Danke für den Link, ich googelte und finde den lua Paketmanager, der mir das Problem gelöst hat. – packetie

Antwort

1

Problem gelöst, nachdem der Paketmanager luarocks Installation und dann Socket-Paket.

Hier sind die Befehle von der Seite

$ 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" 
Verwandte Themen