我想luasql.mysql
用 来安装luarocks
,但遇到了问题。即使安装了提供的软件包mysql.h
,luarocks 也找不到它。我最终解决了它:
luarocks install luasql-mysql MYSQL_INCDIR=/usr/include/mysql
现在,应该满足所有先决条件才能使用luasql.mysql
,但我收到错误:
> require "luasql.mysql"
stdin:1: module 'luasql.mysql' not found:
no field package.preload['luasql.mysql']
no file '/usr/local/share/lua/5.2/luasql/mysql.lua'
no file '/usr/local/share/lua/5.2/luasql/mysql/init.lua'
no file '/usr/local/lib/lua/5.2/luasql/mysql.lua'
no file '/usr/local/lib/lua/5.2/luasql/mysql/init.lua'
no file './luasql/mysql.lua'
no file '/usr/share/lua/5.2/luasql/mysql.lua'
no file '/usr/share/lua/5.2/luasql/mysql/init.lua'
no file './luasql/mysql.lua'
no file '/usr/local/lib/lua/5.2/luasql/mysql.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/luasql/mysql.so'
no file '/usr/lib/lua/5.2/luasql/mysql.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './luasql/mysql.so'
no file '/usr/local/lib/lua/5.2/luasql.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/luasql.so'
no file '/usr/lib/lua/5.2/luasql.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './luasql.so'
stack traceback:
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?
现在,在该列表中,没有/usr/local/lib/luarocks/rocks/
或类似的东西。另外,我似乎找不到mysql.lua
。
根据 luarocks 的说法,luasql-mysql
安装正确:
% luarocks list
Installed rocks:
----------------
luasql-mysql
2.3.0-1 (installed) - /usr/local/lib/luarocks/rocks
我相信我做错了什么,但我不知道哪里做错了。另外,在安装额外的软件包方面,Lua 似乎相当晦涩......
答案1
好吧,我解决了,这是一个相当愚蠢的错误:
luasql.mysql
是仅适用于 Lua 5.1,不是Lua 5.2,我默认使用。运行lua5.1
解决了这个问题:
% lua5.1
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> require "luasql.mysql"
>
...一切都很好。
抱歉造成了混乱...
答案2
您是否尝试过在 LUA 脚本中设置lua.package_cpath
或?lua.package_path
或者设置LUA_CPATH
和LUA_PATH
环境变量?
IEexport LUA_PATH='/usr/local/lib/luarocks/?.so'; lua ./XX.lua