Browse Source

Added table support for love.graphics.setColor (issue #106)

Bart van Strien 14 years ago
parent
commit
a47fa1462d
2 changed files with 26 additions and 4 deletions
  1. 1 0
      changes.txt
  2. 25 4
      src/modules/graphics/opengl/wrap_Graphics.cpp

+ 1 - 0
changes.txt

@@ -20,6 +20,7 @@ LOVE 0.7.0 [Game Slave]
   * Added shape:getBody.
   * Added shape:getBody.
   * Added love.filesystem.FileData for public usage.
   * Added love.filesystem.FileData for public usage.
   * Added base64 support for love.filesystem.FileData.
   * Added base64 support for love.filesystem.FileData.
+  * Added table support for love.graphics.setColor.
 
 
   * Fixed the debug module not being an upvalue of the error handlers. (you can now override debug)
   * Fixed the debug module not being an upvalue of the error handlers. (you can now override debug)
   * Fixed some cases when love.audio.pause and friends, were acting on everything, not just the passed Source.
   * Fixed some cases when love.audio.pause and friends, were acting on everything, not just the passed Source.

+ 25 - 4
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -341,10 +341,31 @@ namespace opengl
 	int w_setColor(lua_State * L)
 	int w_setColor(lua_State * L)
 	{
 	{
 		Color c;
 		Color c;
-		c.r = (unsigned char)luaL_checkint(L, 1);
-		c.g = (unsigned char)luaL_checkint(L, 2);
-		c.b = (unsigned char)luaL_checkint(L, 3);
-		c.a = (unsigned char)luaL_optint(L, 4, 255);
+		if (lua_istable(L, 1)) {
+			lua_pushinteger(L, 1);
+			lua_gettable(L, -2);
+			c.r = (unsigned char)luaL_checkint(L, -1);
+			lua_pop(L, 1);
+			lua_pushinteger(L, 2);
+			lua_gettable(L, -2);
+			c.g = (unsigned char)luaL_checkint(L, -1);
+			lua_pop(L, 1);
+			lua_pushinteger(L, 3);
+			lua_gettable(L, -2);
+			c.b = (unsigned char)luaL_checkint(L, -1);
+			lua_pop(L, 1);
+			lua_pushinteger(L, 4);
+			lua_gettable(L, -2);
+			c.a = (unsigned char)luaL_optint(L, -1, 255);
+			lua_pop(L, 1);
+		}
+		else
+		{
+			c.r = (unsigned char)luaL_checkint(L, 1);
+			c.g = (unsigned char)luaL_checkint(L, 2);
+			c.b = (unsigned char)luaL_checkint(L, 3);
+			c.a = (unsigned char)luaL_optint(L, 4, 255);
+		}
 		instance->setColor(c);
 		instance->setColor(c);
 		return 0;
 		return 0;
 	}
 	}