Alex Szpakowski avatar Alex Szpakowski committed c70c9e4

Cleaned up some Lua binding code

Comments (0)

Files changed (3)

src/modules/graphics/opengl/wrap_Canvas.cpp

 	}
 	else if (lua_istable(L, 2))
 	{
-		lua_pushinteger(L, 1);
-		lua_gettable(L, 2);
+		lua_rawgeti(L, 2, 1);
 		c.r = (unsigned char)luaL_checkint(L, -1);
-		lua_pushinteger(L, 2);
-		lua_gettable(L, 2);
+		lua_rawgeti(L, 2, 2);
 		c.g = (unsigned char)luaL_checkint(L, -1);
-		lua_pushinteger(L, 3);
-		lua_gettable(L, 2);
+		lua_rawgeti(L, 2, 3);
 		c.b = (unsigned char)luaL_checkint(L, -1);
-		lua_pushinteger(L, 4);
-		lua_gettable(L, 2);
+		lua_rawgeti(L, 2, 4);
 		c.g = (unsigned char)luaL_optint(L, -1, 255);
 		lua_pop(L, 4);
 	}

src/modules/graphics/opengl/wrap_Graphics.cpp

 	Color c;
 	if (lua_istable(L, 1))
 	{
-		lua_pushinteger(L, 1);
-		lua_gettable(L, -2);
+		lua_rawgeti(L, 1, 1);
 		c.r = (unsigned char)luaL_checkint(L, -1);
-		lua_pop(L, 1);
-		lua_pushinteger(L, 2);
-		lua_gettable(L, -2);
+		lua_rawgeti(L, 1, 2);
 		c.g = (unsigned char)luaL_checkint(L, -1);
-		lua_pop(L, 1);
-		lua_pushinteger(L, 3);
-		lua_gettable(L, -2);
+		lua_rawgeti(L, 1, 3);
 		c.b = (unsigned char)luaL_checkint(L, -1);
-		lua_pop(L, 1);
-		lua_pushinteger(L, 4);
-		lua_gettable(L, -2);
+		lua_rawgeti(L, 1, 4);
 		c.a = (unsigned char)luaL_optint(L, -1, 255);
-		lua_pop(L, 1);
+		lua_pop(L, 4);
 	}
 	else
 	{
 	Color c;
 	if (lua_istable(L, 1))
 	{
-		lua_pushinteger(L, 1);
-		lua_gettable(L, -2);
+		lua_rawgeti(L, 1, 1);
 		c.r = (unsigned char)luaL_checkint(L, -1);
-		lua_pop(L, 1);
-		lua_pushinteger(L, 2);
-		lua_gettable(L, -2);
+		lua_rawgeti(L, 1, 2);
 		c.g = (unsigned char)luaL_checkint(L, -1);
-		lua_pop(L, 1);
-		lua_pushinteger(L, 3);
-		lua_gettable(L, -2);
+		lua_rawgeti(L, 1, 3);
 		c.b = (unsigned char)luaL_checkint(L, -1);
-		lua_pop(L, 1);
-		lua_pushinteger(L, 4);
-		lua_gettable(L, -2);
+		lua_rawgeti(L, 1, 4);
 		c.a = (unsigned char)luaL_optint(L, -1, 255);
-		lua_pop(L, 1);
+		lua_pop(L, 4);
 	}
 	else
 	{
 
 	if (is_table)
 	{
-		lua_pushinteger(L, 1);
-		lua_gettable(L, 1);
+		lua_rawgeti(L, 1, 1);
 		canvas = luax_checkcanvas(L, -1);
 		lua_pop(L, 1);
 
 		for (int i = 2; i <= lua_objlen(L, 1); i++)
 		{
-			lua_pushinteger(L, i);
-			lua_gettable(L, 1);
+			lua_rawgeti(L, 1, i);
 			attachments.push_back(luax_checkcanvas(L, -1));
 			lua_pop(L, 1);
 		}
 	{
 		for (int i = 0; i < args; ++i)
 		{
-			lua_pushnumber(L, i + 1);
-			lua_rawget(L, 1);
+			lua_rawgeti(L, 1, i + 1);
 			coords[i] = luax_tofloat(L, -1);
 			lua_pop(L, 1);
 		}
 	{
 		for (int i = 0; i < args; ++i)
 		{
-			lua_pushnumber(L, i + 1);
-			lua_rawget(L, 2);
+			lua_rawgeti(L, 2, i + 1);
 			coords[i] = luax_tofloat(L, -1);
 			lua_pop(L, 1);
 		}

src/modules/graphics/opengl/wrap_ParticleSystem.cpp

 				return luaL_argerror(L, i + 2, "expected 4 color components");
 
 			for (int j = 0; j < 4; j++)
-			{
 				// push args[i+2][j+1] onto the stack
-				lua_pushnumber(L, j + 1);
-				lua_gettable(L, i + 2);
-			}
+				lua_rawgeti(L, i + 2, j + 1);
 
 			int r = luaL_checkint(L, -4);
 			int g = luaL_checkint(L, -3);
 	{
 		for (int i = 0; i < nQuads; i++)
 		{
-			lua_pushnumber(L, i + 1); // array index
-			lua_gettable(L, 2);
+			lua_rawgeti(L, 2, i + 1); // array index
 			quads[i] = luax_checkquad(L, -1);
 			lua_pop(L, 1);
 		}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.