lua 5.3.5 安装/初体验
安装
官网http://www.lua.org/start.html 参考 https://blog.csdn.net/qq_23954569/article/details/70879672
cd ~ sudo apt-get install -y libreadline7 libreadline-dev wget http://www.lua.org/ftp/lua-5.3.5.tar.gz tar zxf lua-5.3.5.tar.gz cd lua-5.3.5 sudo make linux test sudo make install
因为放在了home,所以重装之后,只需要执行最后1句就OK了
包管理luarocks
才1M
cd ~ wget https://luarocks.org/releases/luarocks-3.0.4.tar.gz tar zxpf luarocks-3.0.4.tar.gz cd luarocks-3.0.4 ./configure; sudo make bootstrap sudo luarocks install luasocket
安装luasql-postgres
安装时要求本地有postgres源码
Error: Could not find header file for PGSQL
No file libpq-fe.h in /usr/local/include
No file libpq-fe.h in /usr/include
No file libpq-fe.h in /include
You may have to install PGSQL in your system and/or pass PGSQL_DIR or PGSQL_INCDIR to the luarocks command.
Example: luarocks install luasql-postgres PGSQL_DIR=/usr/local
但是我的pg是在docker镜像里的, 所以怎么办呢?要么在host上装pg,但完全没必要.超极本上资源已经很紧了,只写代码,不做数据库.
在安装时指定PG路径, 注意不是PGSQL_DIR
sudo apt-get install libpq-dev sudo luarocks install luasql-postgres PGSQL_INCDIR=/usr/include/postgresql PGSQL_LIBDIR=/usr/lib
连接db简单使用
luasql = require "luasql.postgres" env = assert(luasql.postgres()) -- database user pwd host port conn = assert(env:connect("postgres","postgres","example",'127.0.0.1')) -- version cur = conn:execute("SELECT version();") print(cur:fetch())
—————————————