[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: package question (luasql example)
- From: Tomas <tomas@...>
- Date: Wed, 23 Aug 2006 10:24:25 -0300 (BRT)
Hi Thomas
I have rebuilt luasql & installed. From what I can tell, this operation
creates exactly one file for me : mysql.so (this linked to the longer lib
name) and these exist in usr/lib/luasql.
So, the complete path is /usr/lib/luasql/mysql.so, isn't it?
lua: test.lua:599: could not load package `luasql.mysql' from path
`/home/tblom/.lua50/?.lua;/home/tblom/.lua50/?;/home/tblom/share/lua50/?.lua;/home/tblom/share/lua50/?;/usr/share/lua50/?.lua;/usr/share/lua50/?;/usr/local/share/lua50/?.lua;/usr/local/share/lua50/?;?.lua;?'
Note that the path where the file reside is not mentioned above.
I think you'll need to add "/usr/lib/?.so" to your package.cpath. This
could be done directly in your LUA_CPATH environment variable (but you
could also edit compat-5.1.lua directly).
So I've read up on the 'require' function, and I'm confused as to where
exactly luasql.mysql is supposed to be coming from. Reading in the book I
would assume this would be a .lua file it is looking for, but luasql comes
with no .lua implementation files. I get only the mysql.so. I know this
must be what require('luasql.mysql') in test.lua wants to get at, but I'm not
sure how to provide it.
The documentation of `require' (Lua 5.0 reference manual) will
not enlighten this because Compat-5.1 redefines its behavior. This is due
to the "package model proposal" that arise more than a year before Lua 5.1
was announced. During this period we used Compat to ease the development
of libraries (and also its use and installation process) that will follow
the upcoming behavior. For now, the better documentation is Lua 5.1 :-)
In short, the recommendation is to create a directory to binary
libraries and another one to Lua source libraries (e.g. /usr/lib/lua/5.0)
and /usr/share/lua/5.0/). The package.cpath should point to binary and
package.path to Lua source (e.g. LUA_CPATH="/usr/lib/lua/5.0/?.so;./?.so"
and LUA_PATH="/usr/share/lua/5.0/?.lua;./?.lua"). The function `require'
will call some internal loaders which will try to find a file using the
corresponding path: the Lua loader will try package.path and the C loader
will search in package.cpath. Each of which will use an appropriate function
to load the file. In the case of the C loader, a CFunction would also be
executed; its name is something like "luaopen_<package>", where any '.' in
<package> will be changed to '_' (in a previous version, it was omitted,
therefore your initial problem with luaopen_luasql_mysql).
Regards,
Tomas