Commits

Anonymous committed 1877206

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

  • Participants
  • Parent commits 1fde3f4

Comments (0)

Files changed (1)

src/modules/graphics/opengl/Graphics.cpp

 	bool Graphics::toggleFullscreen()
 	{
 		// Try to do the change.
-		return setMode(currentMode.width,
+		if(!setMode(currentMode.width,
 			currentMode.height,
 			!currentMode.fullscreen,
 			currentMode.vsync,
-			currentMode.fsaa);
+			currentMode.fsaa))
+			return false;
+		currentMode.fullscreen = !currentMode.fullscreen;
+		return true;
 	}
 
 
 
 		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");
+		else if (args < 4)
+			return luaL_error(L, "Need at least two vertices to draw a line");
 
 		// right, let's draw this polyline, then
 		glDisable(GL_TEXTURE_2D);
 		glBegin(GL_LINE_STRIP);
 		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 {
 			for (int i = 1; i < args; i+=2) {