Browse Source

Fix issue #176: unexpected behaivior of love.graphics.line with hash-table argument.

vrld 14 years ago
parent
commit
e7db8c2491
1 changed files with 14 additions and 11 deletions
  1. 14 11
      src/modules/graphics/opengl/Graphics.cpp

+ 14 - 11
src/modules/graphics/opengl/Graphics.cpp

@@ -299,11 +299,14 @@ namespace opengl
 	bool Graphics::toggleFullscreen()
 	bool Graphics::toggleFullscreen()
 	{
 	{
 		// Try to do the change.
 		// Try to do the change.
-		return setMode(currentMode.width,
+		if(!setMode(currentMode.width,
 			currentMode.height,
 			currentMode.height,
 			!currentMode.fullscreen,
 			!currentMode.fullscreen,
 			currentMode.vsync,
 			currentMode.vsync,
-			currentMode.fsaa);
+			currentMode.fsaa))
+			return false;
+		currentMode.fullscreen = !currentMode.fullscreen;
+		return true;
 	}
 	}
 
 
 
 
@@ -826,20 +829,20 @@ namespace opengl
 
 
 		if (args % 2) // an odd number of arguments, no good for a polyline
 		if (args % 2) // an odd number of arguments, no good for a polyline
 			return luaL_error(L, "Number of vertices must be a multiple of two");
 			return luaL_error(L, "Number of vertices must be a multiple of two");
+		else if (args < 4)
+			return luaL_error(L, "Need at least two vertices to draw a line");
 
 
 		// right, let's draw this polyline, then
 		// right, let's draw this polyline, then
 		glDisable(GL_TEXTURE_2D);
 		glDisable(GL_TEXTURE_2D);
 		glBegin(GL_LINE_STRIP);
 		glBegin(GL_LINE_STRIP);
 		if (table) {
 		if (table) {
-			lua_pushnil(L);
-			while (true) {
-				if(lua_next(L, 1) == 0) break;
-				GLfloat x = (GLfloat)lua_tonumber(L, -1);
-				lua_pop(L, 1); // pop value
-				if(lua_next(L, 1) == 0) break;
-				GLfloat y = (GLfloat)lua_tonumber(L, -1);
-				lua_pop(L, 1); // pop value
-				glVertex2f(x, y);
+			for (int i = 1; i < args; i += 2) {
+				lua_pushnumber(L, i);   // x coordinate
+				lua_rawget(L, 1);
+				lua_pushnumber(L, i+1); // y coordinate
+				lua_rawget(L, 1);
+				glVertex2f((GLfloat)lua_tonumber(L, -2), (GLfloat)lua_tonumber(L, -1));
+				lua_pop(L, 2);
 			}
 			}
 		} else {
 		} else {
 			for (int i = 1; i < args; i+=2) {
 			for (int i = 1; i < args; i+=2) {