lua模块安装

lua模块安装可以利用 luarocks 命令,在centos7 上执行以下来安装。

yum install epel-release
yum install luarocks

此时我们安装模块的的时候可能还会报如下错,需要lua开发包来支持编译,因为 luarocks 会先下载源码,然后再编译。

fatal error: lua.h: No such file or directory
 #include "lua.h"
                 ^
compilation terminated
#安装lua开发包
yum install lua-devel

此时我们就可以执行如下指令进行安装了。

luarocks install luasocket
luarocks install luasql-sqlite3
....

但是centos7 非常强大,很多包都已经被前人编译成了rpm包,而无需执行以上麻烦的缓慢的编译安装操作。

所以一般在执行 luarocks 前先尝试利用 yum 安装,安装不成功才会去尝试 luarocks 或者是源码安装。

我们先来查看yum源上有哪些包

[root@localhost ~]# yum search lua-
============================================ N/S matched: lua- ============================================
lua-socket-devel.x86_64 : Development files for lua-socket
texlive-lua-alt-getopt-doc.noarch : Documentation for lua-alt-getopt
ghc-hslua-devel.x86_64 : Haskell hslua library development files
lua-alt-getopt.noarch : Argument processing module for Lua
lua-argparse.noarch : Feature-rich command line parser for Lua
lua-bit32.x86_64 : Backport of Lua bit manipulation library introduced in 5.2
lua-bitop.x86_64 : C extension module for Lua which adds bitwise operations on numbers
lua-cyrussasl.x86_64 : Cyrus SASL library for Lua
lua-dbi.x86_64 : Database interface library for Lua
lua-devel.i686 : Development files for lua
lua-devel.x86_64 : Development files for lua
lua-expat.x86_64 : SAX XML parser based on the Expat library
lua-filesystem.x86_64 : File System Library for the Lua Programming Language
lua-fun.noarch : Functional programming library for Lua
lua-guestfs.x86_64 : Lua bindings for libguestfs
lua-json.noarch : JSON Parser/Constructor for Lua
lua-ldap.x86_64 : LDAP client library for Lua, using OpenLDAP
lua-lpeg.x86_64 : Parsing Expression Grammars for Lua
lua-lunit.noarch : Unit testing framework for Lua
lua-lxc.x86_64 : Lua binding for lxc
lua-md5.x86_64 : Cryptographic Library for MD5 hashes for Lua
lua-mpack.x86_64 : Implementation of MessagePack for Lua
lua-posix.x86_64 : A POSIX library for Lua
lua-prelude.x86_64 : Lua bindings for prelude
lua-sec.x86_64 : Lua binding for OpenSSL library
lua-socket.x86_64 : Network support for the Lua language
lua-static.i686 : Static library for lua
lua-static.x86_64 : Static library for lua
lua-term.x86_64 : Terminal functions for Lua
#接下来按需安装即可如
yum install lua-posix


源码安装luaposix

#找到luaposix的git地址然后clone
[root@192 luaposix]# git clone https://github.com/luaposix/luaposix.git
cd luaposix

#编译安装
build-aux/luke

#然后把so文件拷贝到合适目录
#我的64位centos为如下地址
cd linux
cp -r posix  /usr/lib64/lua/5.1/
local unistd = require("posix.unistd")
unistd.sleep(10)


上一篇: lua coroutine(协程)
下一篇: lua C API(1) - 函数汇总
作者邮箱: 203328517@qq.com