From e7db8c24915b02b1e1b653143fe37667ee911b77 Mon Sep 17 00:00:00 2001 From: vrld Date: Sun, 30 Jan 2011 16:20:31 +0100 Subject: [PATCH] Fix issue #176: unexpected behaivior of love.graphics.line with hash-table argument. --- src/modules/graphics/opengl/Graphics.cpp | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 875f1eac3..1ce4d779d 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -299,11 +299,14 @@ namespace opengl 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; } @@ -826,20 +829,20 @@ namespace opengl 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) {