make local oddness and package.prefix

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

make local oddness and package.prefix

John D. Ramsdell-2
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'

John

Reply | Threaded
Open this post in threaded view
|

Re: make local oddness and package.prefix

Luiz Henrique de Figueiredo
> What would really be nice is if Lua simply told me the prefix used to
> build it.

Perhaps not exactly what you need but Lua 5.1 provides etc/lua.pc
which works with pkg-config.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: make local oddness and package.prefix

Luis Carvalho-2
In reply to this post by John D. Ramsdell-2
> To find the current lua version, one simply types:
> 
> $ lua -v 2>&1 | awk '{print $2}'

lua -e 'print(string.match(_VERSION,"Lua (.*)"))'

> 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--'

lua -e 'print(string.match(package.path,".*;(.*)/share.*"))'

What do you think? It's certainly more portable. ;)

Cheers,
luis.

-- 
A mathematician is a device for turning coffee into theorems.
        -- P. Erdos 

-- 
Luis Carvalho
Applied Math PhD Student - Brown University
PGP Key: E820854A <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: make local oddness and package.prefix

John D. Ramsdell-2
In reply to this post by John D. Ramsdell-2
Luis,

Yes, your trick to compute the prefix

> lua -e 'print(string.match(package.path,".*;(.*)/share.*"))'

is much better than mine.

I still hope that future versions of Lua will supply this information
in a location called package.prefix, rather than making us rely on the
fact that package.path has a particular structure.

John