From f5603b02916198e3aa89bd8f96dd10c4c8743bd3 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Wed, 10 Jul 2013 16:02:52 +0200 Subject: [PATCH] Make love compile against lua5.2 --- platform/unix/configure.ac | 7 +++++-- src/common/runtime.cpp | 7 +++++++ src/common/runtime.h | 5 +++++ src/modules/graphics/opengl/wrap_Graphics.cpp | 2 +- src/modules/graphics/opengl/wrap_Shader.cpp | 12 ++++++------ src/modules/thread/LuaThread.cpp | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/platform/unix/configure.ac b/platform/unix/configure.ac index b2bd68336..8464537dc 100644 --- a/platform/unix/configure.ac +++ b/platform/unix/configure.ac @@ -34,11 +34,14 @@ AC_CHECK_HEADER([freetype2/freetype/config/ftheader.h], [includes="$includes -I/ # Lua, treated seperately because of --with-lua AC_ARG_WITH([lua], [AS_HELP_STRING([--with-lua], [Select the lua implementation])], [], [with_lua=lua]) +AC_ARG_WITH([luaversion], [AS_HELP_STRING([--with-luaversion], [Select the lua version])], + [], [with_luaversion=5.1]) -AC_SEARCH_LIBS([lua_pcall], ["$with_lua" "${with_lua}5.1"], [], +AS_VAR_IF([with_luaversion], [5.2], [luatest=lua_version], [luatest=lua_pcall]) # use lua_version for 5.2 +AC_SEARCH_LIBS([$luatest], ["${with_lua}${with_luaversion}" "${with_lua}"], [], AC_MSG_ERROR([Can't LÖVE without $with_lua])) +AC_CHECK_HEADER(["${with_lua}${with_luaversion}/lua.h"], [includes="$includes -I/usr/include/${with_lua}${with_luaversion}"], []) AC_CHECK_HEADER(["${with_lua}/lua.h"], [includes="$includes -I/usr/include/${with_lua}"], []) -AC_CHECK_HEADER(["${with_lua}5.1/lua.h"], [includes="$includes -I/usr/include/${with_lua}5.1"], []) # mpg123, treated seperately because it can be disabled (default on) AC_ARG_ENABLE([mpg123], AC_HELP_STRING([--disable-mpg123], [Disable mp3 support, for patent-free builds]), [], [enable_mpg123=yes]) diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index e63f2baef..ae8ab8163 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -486,6 +486,13 @@ int luax_getregistry(lua_State *L, Registry r) } } +extern "C" int luax_typerror(lua_State *L, int narg, const char *tname) +{ + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + StringMap::Entry typeEntries[] = { {"Invalid", INVALID_ID}, diff --git a/src/common/runtime.h b/src/common/runtime.h index 6e01e1968..091b66dd3 100644 --- a/src/common/runtime.h +++ b/src/common/runtime.h @@ -26,6 +26,7 @@ // Lua extern "C" { + #define LUA_COMPAT_ALL #include #include #include @@ -346,6 +347,10 @@ int luax_insistlove(lua_State *L, const char *k); **/ int luax_getregistry(lua_State *L, Registry r); +extern "C" { // Also called from luasocket + int luax_typerror(lua_State *L, int narg, const char *tname); +} + /** * Like luax_totype, but causes an error if the value at idx is not Proxy, * or is not the specified type. diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 6fe350f84..8677db80f 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -249,7 +249,7 @@ int w_newGeometry(lua_State *L) vertex v; lua_rawgeti(L, 1, i+1); if (!lua_istable(L, -1)) - return luaL_typerror(L, 1, "table of tables"); + return luax_typerror(L, 1, "table of tables"); for (int j = 1; j <= 8; j++) lua_rawgeti(L, -j, j); diff --git a/src/modules/graphics/opengl/wrap_Shader.cpp b/src/modules/graphics/opengl/wrap_Shader.cpp index 33cf8cac1..3c9407ad4 100644 --- a/src/modules/graphics/opengl/wrap_Shader.cpp +++ b/src/modules/graphics/opengl/wrap_Shader.cpp @@ -58,7 +58,7 @@ static T *_getScalars(lua_State *L, int count, size_t &dimension) else { delete[] values; - luaL_typerror(L, 3 + i, "number or boolean"); + luax_typerror(L, 3 + i, "number or boolean"); return 0; } } @@ -77,7 +77,7 @@ static T *_getVectors(lua_State *L, int count, size_t &dimension) if (!lua_istable(L, 3 + i)) { delete[] values; - luaL_typerror(L, 3 + i, "table"); + luax_typerror(L, 3 + i, "table"); return 0; } if (lua_objlen(L, 3 + i) != dimension) @@ -98,7 +98,7 @@ static T *_getVectors(lua_State *L, int count, size_t &dimension) else { delete[] values; - luaL_typerror(L, -1, "number or boolean"); + luax_typerror(L, -1, "number or boolean"); return 0; } } @@ -125,7 +125,7 @@ int w_Shader_sendInt(lua_State *L) else if (lua_istable(L, 3)) values = _getVectors(L, count, dimension); else - return luaL_typerror(L, 3, "number, boolean, or table"); + return luax_typerror(L, 3, "number, boolean, or table"); if (!values) return luaL_error(L, "Error in arguments."); @@ -162,7 +162,7 @@ int w_Shader_sendFloat(lua_State *L) else if (lua_istable(L, 3)) values = _getVectors(L, count, dimension); else - return luaL_typerror(L, 3, "number, boolean, or table"); + return luax_typerror(L, 3, "number, boolean, or table"); if (!values) return luaL_error(L, "Error in arguments."); @@ -189,7 +189,7 @@ int w_Shader_sendMatrix(lua_State *L) const char *name = luaL_checkstring(L, 2); if (!lua_istable(L, 3)) - return luaL_typerror(L, 3, "matrix table"); + return luax_typerror(L, 3, "matrix table"); lua_getfield(L, 3, "dimension"); int dimension = lua_tointeger(L, -1); diff --git a/src/modules/thread/LuaThread.cpp b/src/modules/thread/LuaThread.cpp index c46b69903..54fdbe625 100644 --- a/src/modules/thread/LuaThread.cpp +++ b/src/modules/thread/LuaThread.cpp @@ -52,7 +52,7 @@ LuaThread::~LuaThread() void LuaThread::threadFunction() { this->retain(); - lua_State * L = lua_open(); + lua_State *L = luaL_newstate(); luaL_openlibs(L); #ifdef LOVE_BUILD_STANDALONE love::luax_preload(L, luaopen_love, "love");