From 55cb2fad84f15b830338ea6ebee354760c84994d Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 31 Jul 2016 11:51:53 -0300 Subject: [PATCH] Fixture:setCategory and Fixture:setMask now accept a table of categories/masks (resolves issue #1178). --- src/modules/physics/box2d/Fixture.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/modules/physics/box2d/Fixture.cpp b/src/modules/physics/box2d/Fixture.cpp index 49689a4be..d56c5a8ef 100644 --- a/src/modules/physics/box2d/Fixture.cpp +++ b/src/modules/physics/box2d/Fixture.cpp @@ -193,16 +193,28 @@ int Fixture::getMask(lua_State *L) uint16 Fixture::getBits(lua_State *L) { // Get number of args. - int argc = lua_gettop(L); + bool istable = lua_istable(L, 1); + int argc = istable ? (int) luax_objlen(L, 1) : lua_gettop(L); // The new bitset. std::bitset<16> b; - for (int i = 1; i<=argc; i++) + for (int i = 1; i <= argc; i++) { - size_t bpos = (size_t)(lua_tointeger(L, i)-1); + size_t bpos = 0; + + if (istable) + { + lua_rawgeti(L, 1, i); + bpos = (size_t) (lua_tointeger(L, -1) - 1); + lua_pop(L, 1); + } + else + bpos = (size_t) (lua_tointeger(L, i) - 1); + if (bpos >= 16) luaL_error(L, "Values must be in range 1-16."); + b.set(bpos, true); }