I generated a patch that solves this problem easily.
diff -Naur elinks-0.12~pre6.orig/configure elinks-0.12~pre6/configure --- elinks-0.12~pre6.orig/configure 2012-10-28 14:00:58.000000000 +0100 +++ elinks-0.12~pre6/configure 2014-01-26 20:39:09.340744616 +0100 @@ -18827,6 +18827,16 @@ if test ! -d "$withval"; then withval=""; fi + if pkg-config lua5.1; then + LUA_CFLAGS=`pkg-config --cflags lua5.1` + LUA_LIBS=`pkg-config --libs lua5.1` + + LIBS="$LUA_LIBS $LIBS_X" + CFLAGS="$CFLAGS_X $LUA_CFLAGS" + CPPFLAGS="$CPPFLAGS_X $LUA_CFLAGS" + + cf_result=yes + fi for luadir in "$withval" "" /usr /usr/local; do for suffix in "" 50; do if test "$cf_result" = no && ( test -f "$luadir/include/lua.h" || \ diff -Naur elinks-0.12~pre6.orig/configure.in elinks-0.12~pre6/configure.in --- elinks-0.12~pre6.orig/configure.in 2012-10-28 13:57:15.000000000 +0100 +++ elinks-0.12~pre6/configure.in 2014-01-26 20:37:19.300741436 +0100 @@ -833,6 +833,16 @@ if test ! -d "$withval"; then withval=""; fi + if pkg-config lua5.1; then + LUA_CFLAGS=`pkg-config --cflags lua5.1` + LUA_LIBS=`pkg-config --libs lua5.1` + + LIBS="$LUA_LIBS $LIBS_X" + CFLAGS="$CFLAGS_X $LUA_CFLAGS" + CPPFLAGS="$CPPFLAGS_X $LUA_CFLAGS" + + cf_result=yes + fi for luadir in "$withval" "" /usr /usr/local; do for suffix in "" 50; do if test "$cf_result" = no && ( test -f "$luadir/include/lua.h" || \ diff -Naur elinks-0.12~pre6.orig/src/scripting/lua/core.c elinks-0.12~pre6/src/scripting/lua/core.c --- elinks-0.12~pre6.orig/src/scripting/lua/core.c 2012-10-28 13:57:15.000000000 +0100 +++ elinks-0.12~pre6/src/scripting/lua/core.c 2014-01-26 20:37:19.300741436 +0100 @@ -658,7 +658,7 @@ if (file_can_read(file)) { int oldtop = lua_gettop(S); - if (lua_dofile(S, file) != 0) + if (luaL_dofile(S, file) != 0) sleep(3); /* Let some time to see error messages. */ lua_settop(S, oldtop); } @@ -671,11 +671,7 @@ { L = lua_open(); - luaopen_base(L); - luaopen_table(L); - luaopen_io(L); - luaopen_string(L); - luaopen_math(L); + luaL_openlibs(L); lua_register(L, LUA_ALERT, l_alert); lua_register(L, "current_url", l_current_url); @@ -780,7 +776,7 @@ int oldtop = lua_gettop(L); if (prepare_lua(ses) == 0) { - lua_dostring(L, expr); + (void) luaL_dostring(L, expr); lua_settop(L, oldtop); finish_lua(); } diff -Naur elinks-0.12~pre6.orig/src/scripting/lua/hooks.c elinks-0.12~pre6/src/scripting/lua/hooks.c --- elinks-0.12~pre6.orig/src/scripting/lua/hooks.c 2012-10-28 13:57:15.000000000 +0100 +++ elinks-0.12~pre6/src/scripting/lua/hooks.c 2014-01-26 20:37:19.300741436 +0100 @@ -200,7 +200,7 @@ script_hook_quit(va_list ap, void *data) { if (!prepare_lua(NULL)) { - lua_dostring(lua_state, "if quit_hook then quit_hook() end"); + (void) luaL_dostring(lua_state, "if quit_hook then quit_hook() end"); finish_lua(); }