安装luasocket
1).Lua 模块的安装和部署工具 LuaRocks
$sudo apt-get install luarocks #安装部署工具 LuaRocks
$luarocks install luasocket
2).源码下载编译、安装
$git clone https://github.com/diegonehab/luasocket.git
$cd luasocket
$make
$make install-both
$make test #如果显示如下信息,恭喜你安装成功了!
lua test/hello.lua
Hello from LuaSocket 3.0-rc1 and MIME 1.0.3!
# luasocket makefile
#
# see src/makefile for description of how to customize the build
#
# Targets:
# install install system independent support
# install-unix also install unix-only support
# install-both install for lua51 lua52 lua53
# install-both-unix also install unix-only
# print print the build settings
简单测试:
//luasocket_test.lua
#!/usr/local/bin/lua
local socket = require("socket")
print("hello luasocket")
print(socket._VERSION) --输出luasocket版本信息
--运行结果(版本信息以实际安装版本为准)
hello luasocket
LuaSocket 3.0-rc1