Mercurial > love-experiments
changeset 1417:c70c9e4d10f3
Cleaned up some Lua binding code
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Sun, 31 Mar 2013 04:55:03 -0300 |
| parents | 0e995de9261c |
| children | 357697c2e2a8 |
| files | src/modules/graphics/opengl/wrap_Canvas.cpp src/modules/graphics/opengl/wrap_Graphics.cpp src/modules/graphics/opengl/wrap_ParticleSystem.cpp |
| diffstat | 3 files changed, 20 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/src/modules/graphics/opengl/wrap_Canvas.cpp Sun Mar 31 00:31:21 2013 -0300 +++ b/src/modules/graphics/opengl/wrap_Canvas.cpp Sun Mar 31 04:55:03 2013 -0300 @@ -179,17 +179,13 @@ } 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); }
--- a/src/modules/graphics/opengl/wrap_Graphics.cpp Sun Mar 31 00:31:21 2013 -0300 +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp Sun Mar 31 04:55:03 2013 -0300 @@ -601,22 +601,15 @@ 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 @@ 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 @@ 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 @@ { 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 @@ { 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); }
--- a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp Sun Mar 31 00:31:21 2013 -0300 +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp Sun Mar 31 04:55:03 2013 -0300 @@ -248,11 +248,8 @@ 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 @@ { 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); }
