Browse Source

Add Body:getFilterList

--HG--
branch : box2d-update
Bill Meltsner 14 years ago
parent
commit
221d9699f6

+ 15 - 0
src/modules/physics/box2d/Body.cpp

@@ -394,6 +394,21 @@ namespace box2d
 	{
 		return world;
 	}
+	
+	int Body::getFixtureList(lua_State * L) const
+	{
+		lua_newtable(L);
+		b2Fixture * f = body->GetFixtureList();
+		int i = 1;
+		do {
+			if (!f) break;
+			Fixture * fixture = (Fixture *)Memoizer::find(f);
+			if (!fixture) throw love::Exception("A fixture has escaped Memoizer!");
+			luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture);
+			lua_rawseti(L, -1, i);
+		} while ((f = f->GetNext()));
+		return 1;
+	}
 
 	b2Vec2 Body::getVector(lua_State * L)
 	{

+ 7 - 0
src/modules/physics/box2d/Body.h

@@ -378,6 +378,13 @@ namespace box2d
 		* Get the World this Body resides in.
 		*/
 		World * getWorld() const;
+		
+		/**
+		* Get an array of all the Fixtures attached to this Body.
+		* @return An array of Fixtures.
+		**/
+		int getFixtureList(lua_State * L) const;
+		
 	private:
 
 		/**

+ 8 - 0
src/modules/physics/box2d/wrap_Body.cpp

@@ -499,6 +499,13 @@ namespace box2d
 		luax_pushboolean(L, b);
 		return 1;
 	}
+	
+	int w_Body_getFixtureList(lua_State * L)
+	{
+		Body * t = luax_checkbody(L, 1);
+		lua_remove(L, 1);
+		return t->getFixtureList(L);
+	}
 
 	int w_Body_destroy(lua_State * L)
 	{
@@ -561,6 +568,7 @@ namespace box2d
 		{ "setAwake", w_Body_setAwake },
 		{ "setFixedRotation", w_Body_setFixedRotation },
 		{ "isFixedRotation", w_Body_isFixedRotation },
+		{ "getFixtureList", w_Body_getFixtureList },
 		{ "destroy", w_Body_destroy },
 		{ 0, 0 }
 	};

+ 1 - 0
src/modules/physics/box2d/wrap_Body.h

@@ -82,6 +82,7 @@ namespace box2d
 	int w_Body_setAwake(lua_State * L);
 	int w_Body_setFixedRotation(lua_State * L);
 	int w_Body_isFixedRotation(lua_State * L);
+	int w_Body_getFixtureList(lua_State * L);
 	int w_Body_destroy(lua_State * L);
 	int luaopen_body(lua_State * L);