diff --git a/configure.ac b/configure.ac index ad3a60bb1..411da0b55 100644 --- a/configure.ac +++ b/configure.ac @@ -261,19 +261,20 @@ AC_ARG_ENABLE(lua, if test "$enable_lua" = "yes"; then AC_DEFINE(ENABLE_LUA, 1, [include Lua support]) - PKG_CHECK_MODULES([LUA], [lua >= 5.2], [ - echo "lua >= 5.2 found" - ], [ - PKG_CHECK_MODULES([LUA], [lua5.2 >= 5.2], [ - echo "lua5.2 found" - ], [ + PKG_CHECK_MODULES(LUA, lua, LLUA="yes", LLUA="no") + PKG_CHECK_MODULES(luajit, luajit, LLUAJIT="yes", LLUAJIT="no") + if test "x$LLUAJIT" = "xyes"; then + LUA_LIBS="-lluajit-5.1" + AC_DEFINE(LUA_COMPAT_5_2, 1, [needed for build with lua 5.1]) + elif test "x$LLUA" = "xyes"; then + LUA_LIBS="-llua" + AC_DEFINE(LUA_COMPAT_5_2, 0, [needed for build with lua 5.1]) + else echo "lualib not found, assuming static lua in linker path..." LUA_LIBS="-llua -ldl" AC_DEFINE(STATIC_LUAPOSIX, 1, [Define to 1 for static lua build.]) - ]) - ]) - # hack... - AC_DEFINE(LUA_COMPAT_5_2, 1, [does not really belong in config.h, but is needed for build with lua 5.3+]) + AC_DEFINE(LUA_COMPAT_5_2, 0, [needed for build with lua 5.1]) + fi fi AM_CONDITIONAL(ENABLE_LUA, test "$enable_lua" = "yes") diff --git a/src/gui/lua/lua_threads.h b/src/gui/lua/lua_threads.h index 324e43ccd..4e87886b3 100644 --- a/src/gui/lua/lua_threads.h +++ b/src/gui/lua/lua_threads.h @@ -31,12 +31,17 @@ extern "C" #include } #include +#include /* wrap strerror_r(). */ #ifndef strerror_r #define strerror_r __strerror_r #endif +#if LUA_COMPAT_5_2 +void lua_rawsetp (lua_State *L, int i, const void *p); +#endif + #define OS_THREAD_RETURN void * #define INFINITE_JOIN_TIMEOUT -1 #define JOIN_OK 0 diff --git a/src/gui/lua/lua_video.h b/src/gui/lua/lua_video.h index da0128950..4cfe08e03 100644 --- a/src/gui/lua/lua_video.h +++ b/src/gui/lua/lua_video.h @@ -20,6 +20,10 @@ #ifndef _LUAVIDEO_H #define _LUAVIDEO_H +#if LUA_COMPAT_5_2 +void lua_rawsetp (lua_State *L, int i, const void *p); +#endif + class CLuaVideo { public: diff --git a/src/gui/lua/luainstance.cpp b/src/gui/lua/luainstance.cpp index dc9576a56..822d87da9 100644 --- a/src/gui/lua/luainstance.cpp +++ b/src/gui/lua/luainstance.cpp @@ -1245,4 +1245,41 @@ int CLuaInstance::scale2Res(lua_State *L) return 1; } +#if LUA_COMPAT_5_2 + +void lua_pushunsigned (lua_State *L, lua_Unsigned n) { + lua_pushnumber(L, lua_unsigned2number(n)); +} + + +lua_Unsigned luaL_checkunsigned (lua_State *L, int i) { + lua_Unsigned result; + lua_Number n = lua_tonumber(L, i); + if (n == 0 && !lua_isnumber(L, i)) + luaL_checktype(L, i, LUA_TNUMBER); + lua_number2unsigned(result, n); + return result; +} + +int lua_absindex (lua_State *L, int i) { + if (i < 0 && i > LUA_REGISTRYINDEX) + i += lua_gettop(L) + 1; + return i; +} + +void lua_rawgetp (lua_State *L, int i, const void *p) { + int abs_i = lua_absindex(L, i); + lua_pushlightuserdata(L, (void*)p); + lua_rawget(L, abs_i); +} + +void lua_rawsetp (lua_State *L, int i, const void *p) { + int abs_i = lua_absindex(L, i); + luaL_checkstack(L, 1, "not enough stack slots"); + lua_pushlightuserdata(L, (void*)p); + lua_insert(L, -2); + lua_rawset(L, abs_i); +} + +#endif /* --------------------------------------------------------------- */ diff --git a/src/gui/lua/luainstance_helpers.h b/src/gui/lua/luainstance_helpers.h index b742ade10..14dc5ad9c 100644 --- a/src/gui/lua/luainstance_helpers.h +++ b/src/gui/lua/luainstance_helpers.h @@ -23,6 +23,31 @@ #include +#if LUA_COMPAT_5_2 + +#include +#include + +typedef uint32_t lua_Unsigned; +int lua_absindex (lua_State *L, int i); +void lua_rawgetp (lua_State *L, int i, const void *p); +void lua_rawsetp (lua_State *L, int i, const void *p); +void lua_pushunsigned (lua_State *L, lua_Unsigned n); +lua_Unsigned luaL_checkunsigned (lua_State *L, int i); +#define lua_pushglobaltable(L) \ + lua_pushvalue(L, LUA_GLOBALSINDEX) + +#define LUA_SUPUNSIGNED \ + ((lua_Number)(~(lua_Unsigned)0) + 1) + +#define lua_number2unsigned(i,n) \ + ((i) = (lua_Unsigned)(n)) + +#define lua_unsigned2number(u) \ + (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u)) + +#endif + //#define LUA_DEBUG printf #define LUA_DEBUG(...)