先安裝一下包管理工具
yum install luarocks lua-devel -y
luarocks install lpack
ln -s /usr/lib64/lua /usr/local/lib
指定luarocks安裝路徑引數備忘
luarocks install lpack --tree=/usr/local/lib64
測試一下包安裝有沒有問題
/usr/local/openresty/bin/resty -e "require 'pack'"
我想是沒有問題了,,順便測試一下pack
require"pack" bpack=string.pack bunpack=string.unpack function hex(s) s=string.gsub(s,"(.)",function (x) return string.format("%02X",string.byte(x)) end) return s end a=bpack("Ab8","\027Lua",5*16+1,0,1,4,4,4,8,0) --print(hex(a),string.len(a)) b=string.dump(hex) b=string.sub(b,1,string.len(a)) print(a==b,string.len(b)) print(bunpack(b,"bA3b8")) i=314159265 f="<I>I=I" a=bpack(f,i,i,i) --print(hex(a)) print(bunpack(a,f)) i=3.14159265 f="<d>d=d" a=bpack(f,i,i,i) --print(hex(a)) print(bunpack(a,f))