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())

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM