From eef4eed636d29e51798143d09af31a3eedfbb860 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 31 Mar 2013 04:55:03 -0300 Subject: [PATCH] Cleaned up some Lua binding code --- src/modules/graphics/opengl/wrap_Canvas.cpp | 12 ++--- src/modules/graphics/opengl/wrap_Graphics.cpp | 46 ++++++------------- .../graphics/opengl/wrap_ParticleSystem.cpp | 8 +--- 3 files changed, 20 insertions(+), 46 deletions(-) diff --git a/src/modules/graphics/opengl/wrap_Canvas.cpp b/src/modules/graphics/opengl/wrap_Canvas.cpp index 991dc8b66..b32d38173 100644 --- a/src/modules/graphics/opengl/wrap_Canvas.cpp +++ b/src/modules/graphics/opengl/wrap_Canvas.cpp @@ -179,17 +179,13 @@ int w_Canvas_clear(lua_State *L) } 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); } diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 5334153ad..2a7700592 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -601,22 +601,15 @@ int w_setColor(lua_State *L) 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 { @@ -644,22 +637,15 @@ int w_setBackgroundColor(lua_State *L) 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 { @@ -999,15 +985,13 @@ int w_setCanvases(lua_State *L) 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); } @@ -1289,8 +1273,7 @@ int w_line(lua_State *L) { 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); } @@ -1392,8 +1375,7 @@ int w_polygon(lua_State *L) { 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); } diff --git a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp index 1287b833d..9b4b8c829 100644 --- a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp @@ -248,11 +248,8 @@ int w_ParticleSystem_setColors(lua_State *L) 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); @@ -325,8 +322,7 @@ int w_ParticleSystem_setQuads(lua_State *L) { 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); }