Linking with Lua the best way

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

Linking with Lua the best way

Rasmus Neckelmann
Hello,

I know this question isn't related to the Lua language itself, but
rather to various linux distributions and how the Lua library is made
available on them; but I hope I can get some help here anyway.

My problem is that I've recently started getting quite a lot of bug
reports from people who complain my game won't compile anymore, due to
some Lua issues. I've figured out what all those people have in
common, namely the fact that they've just upgraded from Lua 5.0 to Lua
5.1. I know it's not Lua's fault that some Linux distributions don't
offer packages like liblua50 and liblua51, but instead just have a
single package called something like liblua; it's annoying none the
less.

Currently my configure (autoconf) script works by looking for both
liblua and liblua50, and simply links with anything it can find, and
includes any header files it can find (sometimes found in #include
<lua50/*>, sometimes found in #include <lua/*>, and sometimes found
only in #include <*>).
This worked fine when everybody was just using Lua 5.0, but now some
people are using Lua 5.1 which isn't backward compatible.

Of course I could just use the new Lua libraries instead (i.e. stop
using some macros), but what when Lua 5.2 comes out and it's the same
problem all over again? And, frankly, I don't feel like changing stuff
in my current code, as it works fine as it is. (if there's
security/bug-fixes in Lua 5.1, I hope they're released for Lua 5.0
too, so people don't need to change API to be up to date).
Another thing is that my game project might not be as active when Lua
5.2 comes out, so maybe there'll be none to fix it.

I hope there's a neat way to handle this problem, and maybe someone
who can redirect me to some autoconf code which can do it. Well, is
there? :)

Here's a snippet from my configure.in:

AC_SEARCH_LIBS(lua_pushboolean,lua lua50, [], [AC_MSG_ERROR(liblua50
or liblua required)])
AC_SEARCH_LIBS(luaopen_math,lualib lualib50, [],
[AC_MSG_ERROR(liblualib50 or liblualib required)])

AC_CHECK_HEADER(lua50/lua.h,AC_DEFINE(HAVE_LUA50_LUA_H),[])
AC_CHECK_HEADER(lua50/lauxlib.h,AC_DEFINE(HAVE_LUA50_LAUXLIB_H),[])
AC_CHECK_HEADER(lua50/lualib.h,AC_DEFINE(HAVE_LUA50_LUALIB_H),[])

AC_CHECK_HEADER(lua/lua.h,AC_DEFINE(HAVE_LUA_LUA_H),[])
AC_CHECK_HEADER(lua/lauxlib.h,AC_DEFINE(HAVE_LUA_LAUXLIB_H),[])
AC_CHECK_HEADER(lua/lualib.h,AC_DEFINE(HAVE_LUA_LUALIB_H),[])

AC_CHECK_HEADER(lua.h,AC_DEFINE(HAVE_LUA_H),[])
AC_CHECK_HEADER(lauxlib.h,AC_DEFINE(HAVE_LAUXLIB_H),[])
AC_CHECK_HEADER(lualib.h,AC_DEFINE(HAVE_LUALIB_H),[])

And this is where the headers are pulled in:

    #if defined(HAVE_LUA50_LUA_H)
      #include <lua50/lua.h>
    #elif defined(HAVE_LUA_LUA_H)
      #include <lua/lua.h>
    #elif defined(HAVE_LUA_H)
      #include <lua.h>
    #else
      #error Missing lua.h
    #endif

    #if defined(HAVE_LUA50_LAUXLIB_H)
      #include <lua50/lauxlib.h>
    #elif defined(HAVE_LUA_LAUXLIB_H)
      #include <lua/lauxlib.h>
    #elif defined(HAVE_LAUXLIB_H)
      #include <lauxlib.h>
    #else
      #error Missing lauxlib.h
    #endif

    #if defined(HAVE_LUA50_LUALIB_H)
      #include <lua50/lualib.h>
    #elif defined(HAVE_LUA_LUALIB_H)
      #include <lua/lualib.h>
    #elif defined(HAVE_LUALIB_H)
      #include <lualib.h>
    #else
      #error Missing lualib.h
    #endif

Thanks in advance!

--
Cheers,
Rasmus Neckelmann
Reply | Threaded
Open this post in threaded view
|

Re: Linking with Lua the best way

Luiz Henrique de Figueiredo
Your best bet is to link Lua statically into your program. To ensure you
have the correct version, distribute Lua with your program.

BTW, why doesn't your program compile and run fine under Lua 5.1?
--lhf
Reply | Threaded
Open this post in threaded view
|

Re: Linking with Lua the best way

Rasmus Neckelmann
On 5/30/06, Luiz Henrique de Figueiredo <[hidden email]> wrote:
> Your best bet is to link Lua statically into your program. To ensure you
> have the correct version, distribute Lua with your program.

I did that originally, but then some linux package maintainers started
complaining that all programs should link dynamically with libraries
:)
Of course, if that's the best bet I'll consider it again.

> BTW, why doesn't your program compile and run fine under Lua 5.1?

Specifically it complains about lack of luaL_check_number (and
possibly other macros). Some googling told me that this macro have
been removed from Lua 5.1.

--
Cheers,
Rasmus Neckelmann
Reply | Threaded
Open this post in threaded view
|

Re: Linking with Lua the best way

Luiz Henrique de Figueiredo
> I did that originally, but then some linux package maintainers started
> complaining that all programs should link dynamically with libraries

I don't think this applies to Lua. But there has been some discussion
about this issue here. Check the archives.
 
> Specifically it complains about lack of luaL_check_number (and
> possibly other macros). Some googling told me that this macro have
> been removed from Lua 5.1.

I'm sorry. I don't know why lauxlib.h did not contain a compatibility
section. In any case, it's simple to fix. If you can move to 5.1,
and need help, just shout.
--lhf
Reply | Threaded
Open this post in threaded view
|

RE: Linking with Lua the best way

Jerome Vuarand-2
In reply to this post by Rasmus Neckelmann
Google told me it was removed in Lua 5. The correct name is luaL_checknumber. I found that in 5.0.2 sources:
lua-5.0.2/include/lauxlib.h:132:#define luaL_check_number       luaL_checknumber
I guess there it's a compability macro in 5.0 that has been removed in 5.1. luaL_checknumber is ok in 5.0 too, so if you don't need Lua4.x support use the luaL_check* instead of luaL_check_*.

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Rasmus Neckelmann
Envoyé : 30 mai 2006 15:10
À : Lua list
Objet : Re: Linking with Lua the best way

On 5/30/06, Luiz Henrique de Figueiredo <[hidden email]> wrote:
> Your best bet is to link Lua statically into your program. To ensure
> you have the correct version, distribute Lua with your program.

I did that originally, but then some linux package maintainers started complaining that all programs should link dynamically with libraries
:)
Of course, if that's the best bet I'll consider it again.

> BTW, why doesn't your program compile and run fine under Lua 5.1?

Specifically it complains about lack of luaL_check_number (and possibly other macros). Some googling told me that this macro have been removed from Lua 5.1.

--
Cheers,
Rasmus Neckelmann