Mercurial > love-experiments
diff src/modules/graphics/opengl/wrap_ParticleSystem.cpp @ 1353:c3c9d6ed3e21 particlesystem-quads
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Mon, 11 Mar 2013 01:44:43 -0300 |
| parents | 470a47bebfb3 |
| children | b88c88225336 f1c353a5067d |
line wrap: on
line diff
--- a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp Sun Mar 10 03:40:25 2013 -0300 +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp Mon Mar 11 01:44:43 2013 -0300 @@ -266,26 +266,38 @@ int w_ParticleSystem_setQuads(lua_State *L) { ParticleSystem *t = luax_checkparticlesystem(L, 1); + int nQuads = lua_gettop(L) - 1; + if (lua_istable(L, 2)) + nQuads = lua_objlen(L, 2); + // Remove all quads if no argument is given. if (nQuads == 0) - t->setQuad(); - else if (nQuads == 1) { - love::graphics::Quad *q = luax_checkframe(L, 2); - t->setQuad(q); + t->setQuads(); + return 0; + } + + std::vector<love::graphics::Quad *> quads(nQuads); + + if (lua_istable(L, 2)) + { + for (int i = 0; i < nQuads; i++) + { + lua_pushnumber(L, i + 1); // array index + lua_gettable(L, 2); + quads[i] = luax_checkframe(L, -1); + lua_pop(L, 1); + } } else { - std::vector<love::graphics::Quad *> quads(nQuads); - for (size_t i = 0; i < nQuads; i++) - { - love::graphics::Quad *q = luax_checkframe(L, i + 2); - quads[i] = q; - } - t->setQuad(quads); + for (int i = 0; i < nQuads; i++) + quads[i] = luax_checkframe(L, i + 2); } + t->setQuads(quads); + return 0; }
