0
0
mirror of https://github.com/rkd77/elinks.git synced 2025-06-30 22:19:29 -04:00

configure.in, lua: check for lua51 first. When both lua50 and lua51

are installed lua51 is preferred.
This commit is contained in:
Witold Filipczyk 2007-07-22 22:43:24 +02:00 committed by Witold Filipczyk
parent ef198d2105
commit d83989343a
3 changed files with 48 additions and 12 deletions

View File

@ -879,6 +879,7 @@ dnl ===================================================================
dnl Do this the long way, as FreeBSD reportedly needs -L<dir> for
dnl anything other than /usr/lib, and Lua is very often in /usr/local/lib.
dnl Check for Lua51 first. Support for Lua50 will be removed in 0.13.
AC_ARG_WITH(lua, [ --without-lua disable Lua support],
[if test "$withval" = no; then disable_lua=yes; fi])
@ -892,10 +893,10 @@ if test -z "$disable_lua"; then
withval="";
fi
for luadir in "$withval" "" /usr /usr/local; do
for suffix in "" 50 51; do
for suffix in "" 51 50; do
if test "$cf_result" = no && ( test -f "$luadir/include/lua.h" || \
test -f "$luadir/include/lua$suffix/lua.h" ) ; then
LUA_LIBS="-L$luadir/lib -llua$suffix -llualib$suffix -lm"
LUA_LIBS="-L$luadir/lib -llua$suffix -lm"
LUA_CFLAGS="-I$luadir/include -I$luadir/include/lua$suffix"
LIBS="$LUA_LIBS $LIBS_X"
@ -903,15 +904,29 @@ if test -z "$disable_lua"; then
CPPFLAGS="$CPPFLAGS_X $LUA_CFLAGS"
# Check that it is a compatible Lua version
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <lua.h>
#include <lualib.h>]], [[ lua_State *L = lua_open();
luaopen_base(L);
luaopen_table(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(L);
lua_pushboolean(L, 1);
lua_close(L);]])],[cf_result=yes],[cf_result=no])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <lua.h>
#include <lualib.h>]], [[lua_State *L = lua_open();
luaopen_base(L);
luaopen_table(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(L);
lua_pushboolean(L, 1);
lua_close(L);]])],[cf_result=yes],[
LUA_LIBS="-L$luadir/lib -llua$suffix -llualib$suffix -lm"
LIBS="$LUA_LIBS $LIBS_X"
# Check that it is a compatible Lua version
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <lua.h>
#include <lualib.h>]], [[lua_State *L = lua_open();
luaopen_base(L);
luaopen_table(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(L);
lua_pushboolean(L, 1);
lua_close(L);]])],[cf_result=yes],[cf_result=no])])
fi
done
done

View File

@ -49,6 +49,9 @@
#define LUA_HOOKS_FILENAME "hooks.lua"
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
#define ELINKS_LUA_51
#endif
lua_State *lua_state;
@ -657,8 +660,11 @@ do_hooks_file(LS, unsigned char *prefix, unsigned char *filename)
* Fixes debian bug #231760 ('dbug 231760' using URI rewrite) */
if (file_can_read(file)) {
int oldtop = lua_gettop(S);
#ifdef ELINKS_LUA_51
if (luaL_dofile(S, file) != 0)
#else
if (lua_dofile(S, file) != 0)
#endif
sleep(3); /* Let some time to see error messages. */
lua_settop(S, oldtop);
}
@ -671,11 +677,15 @@ init_lua(struct module *module)
{
L = lua_open();
#ifdef ELINKS_LUA_51
luaL_openlibs(L);
#else
luaopen_base(L);
luaopen_table(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(L);
#endif
lua_register(L, LUA_ALERT, l_alert);
lua_register(L, "current_url", l_current_url);
@ -780,7 +790,11 @@ handle_ret_eval(struct session *ses)
int oldtop = lua_gettop(L);
if (prepare_lua(ses) == 0) {
#ifdef ELINKS_LUA_51
if (luaL_dostring(L, expr));
#else
lua_dostring(L, expr);
#endif
lua_settop(L, oldtop);
finish_lua();
}

View File

@ -15,6 +15,9 @@
#include "session/session.h"
#include "util/string.h"
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
#define ELINKS_LUA_51
#endif
/* The events that will trigger the functions below and what they are expected
* to do is explained in doc/events.txt */
@ -200,7 +203,11 @@ static enum evhook_status
script_hook_quit(va_list ap, void *data)
{
if (!prepare_lua(NULL)) {
#ifdef ELINKS_LUA_51
if (luaL_dostring(lua_state, "if quit_hook then quit_hook() end"));
#else
lua_dostring(lua_state, "if quit_hook then quit_hook() end");
#endif
finish_lua();
}