[记录点滴]编译安装luarocks、luacheck、luautf8
[记录点滴]编译安装luarocks、luacheck、luautf8
0x00 摘要
记录一次安装luarocks&第三方库的过程。
0x01 luarocks
如今每个语言体系中都有一个包管理工具,PHP的Composer,Ruby的gem,Python的pip,lua第三方包管理工具就是luarocks。
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 --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1/
sudo make bootstrap
编译安装
mkdir -p "/usr/local/share/lua/5.1//luarocks"
cp src/luarocks/site_config.lua "/usr/local/share/lua/5.1//luarocks"
mkdir -p "/usr/local"
查看
which luarocks
/usr/local/bin/luarocks
0x02 安装luacheck
luacheck 是google推出的一款针对lua静态检查的开源工具,其安装简单,操作容易,检查严格,参数可控,很适合项目的lua开发。
luarocks install luacheck --- 成功
下面是luacheck git网址,留作备份
https://github.com/mpeterv/luacheck/
0x03 安装utf8第三方库
从这里下载 https://github.com/starwing/luautf8
Note that to avoid conflict with the Lua5.3's buitin library 'utf8', this library produce a file like lua-utf8.dll or lua-utf8.so. so use it like this:
local utf8 = require 'lua-utf8'
in your codes :-(
LuaRocks Installation
luarocks install luautf8
It's now full-compatible with Lua5.3's utf8 library, so replace this file (and headers) with lua5.3 source's lutf8lib.c is also okay.
安装
luarocks install luautf8
Installing https://luarocks.org/luautf8-0.1.1-1.src.rock
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1/ -c lutf8lib.c -o lutf8lib.o
gcc -shared -o lua-utf8.so -L/usr/lib lutf8lib.o
luautf8 0.1.1-1 is now installed in /usr/local (license: MIT)
最后发现位置是:
$ find . -name "lua-utf8.so"
./usr/local/lib/lua/5.1/lua-utf8.so
./srv/lua/xxxx/libs/unix/lua-utf8.so
在lua中测试:
local UTF8 = require "util.misc.utf8"
local u = UTF8.escape
ngx.say(RESPONSE.error(-1, u"%123%u123%{123}%u{123}%xABC%x{ABC}", 404))
ngx.say(RESPONSE.error(-1, u"%%123%?%d%%u", 404))
print(u"%123%u123%{123}%u{123}%xABC%x{ABC}")
print(u"%%123%?%d%%u")
得到response是:
{"code":-1,"data":{"status":404},"message":"{{{{઼઼"}
{"code":-1,"data":{"status":404},"message":"%123?d%u"}