Add Body:getFilterList

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-24 17:12:45 -04:00
parent 15d2b7c63d
commit 221d9699f6
4 changed files with 31 additions and 0 deletions
+15
View File
@@ -395,6 +395,21 @@ namespace box2d
return world; 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) b2Vec2 Body::getVector(lua_State * L)
{ {
love::luax_assert_argc(L, 2, 2); love::luax_assert_argc(L, 2, 2);
+7
View File
@@ -378,6 +378,13 @@ namespace box2d
* Get the World this Body resides in. * Get the World this Body resides in.
*/ */
World * getWorld() const; 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: private:
/** /**
+8
View File
@@ -500,6 +500,13 @@ namespace box2d
return 1; 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) int w_Body_destroy(lua_State * L)
{ {
Proxy * p = (Proxy *)lua_touserdata(L, 1); Proxy * p = (Proxy *)lua_touserdata(L, 1);
@@ -561,6 +568,7 @@ namespace box2d
{ "setAwake", w_Body_setAwake }, { "setAwake", w_Body_setAwake },
{ "setFixedRotation", w_Body_setFixedRotation }, { "setFixedRotation", w_Body_setFixedRotation },
{ "isFixedRotation", w_Body_isFixedRotation }, { "isFixedRotation", w_Body_isFixedRotation },
{ "getFixtureList", w_Body_getFixtureList },
{ "destroy", w_Body_destroy }, { "destroy", w_Body_destroy },
{ 0, 0 } { 0, 0 }
}; };
+1
View File
@@ -82,6 +82,7 @@ namespace box2d
int w_Body_setAwake(lua_State * L); int w_Body_setAwake(lua_State * L);
int w_Body_setFixedRotation(lua_State * L); int w_Body_setFixedRotation(lua_State * L);
int w_Body_isFixedRotation(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 w_Body_destroy(lua_State * L);
int luaopen_body(lua_State * L); int luaopen_body(lua_State * L);