Browse Source

Make love compile against lua5.2

Bart van Strien 12 years ago
parent
commit
f5603b0291

+ 5 - 2
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])

+ 7 - 0
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<Type, TYPE_MAX_ENUM>::Entry typeEntries[] =
 {
 	{"Invalid", INVALID_ID},

+ 5 - 0
src/common/runtime.h

@@ -26,6 +26,7 @@
 
 // Lua
 extern "C" {
+	#define LUA_COMPAT_ALL
 	#include <lua.h>
 	#include <lualib.h>
 	#include <lauxlib.h>
@@ -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.

+ 1 - 1
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);

+ 6 - 6
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<int>(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<float>(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);

+ 1 - 1
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");