lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I normally use Lua on Fedora Core, and install it with "yum install
lua".  If I write a package that requires Lua, one can add Lua as a
prerequisite, and the package installer will automatically ensure Lua
is present.  It's all very nice and simple.  My thanks go out to the
person who packaged Lua 5.02.  Note that Lua 5.02 is installed with a
prefix of /usr, not /usr/local, following Red Hat's convention.  They
get to decide.

I decided to play with Lua 5.1, and see how I might want to change my
Lua programs, and in particular, make use of the new Lua package
system.  So I built Lua 5.1 from the sources by typing "make local",
placed the package aware version of my Lua program in ./share/lua/5.1,
but found that ./bin/lua was unable to find my program!  It turns out
"make local" created a lua executable that thought its prefix was
/usr/local, not `pwd`!  Not what one would expect.

This little exercise made me realized there is no simple way to ask
lua to report the prefix used to determine the location in which to
install scripts.  I do not have access to root on some machines on
which I would like to use Lua, so I often install software with a
prefix of $HOME.  In other cases, we use a different prefix for each
collection of components on which the software depends.  For example,
I might use a prefix of $HOME/old to test a system built with an old
version of expat, while $HOME/new might contain the 2.0 release.  I
would like to build my makefile so it automatically detects the
correct location for installed scripts.

To find the current lua version, one simply types:

$ lua -v 2>&1 | awk '{print $2}'

So far, the best way I know how to find the current lua prefix is:

$ lua -e 'print(package.path)' \
  | awk -F\; '{print $2}' \
  | sed 's-/share/lua/5\.1/?\.lua--'

The output from the above two commands can be assembled into a
directory for installed scripts as $PREFIX/share/lua/$VERSION.

What would really be nice is if Lua simply told me the prefix used to
build it.  Just as Python provides sys.prefix, I think Lua should
provide package.prefix.  Makefile authors will rejoice.  It's so easy
in Python, just type:

$ python -c 'import sys; print sys.prefix'