bounds check ChainShape:getPoint, and make functions that take indices 1-indexed on the Lua end of things

This commit is contained in:
Bill Meltsner
2012-02-04 19:38:11 -05:00
parent 83f7002f67
commit ddb1492c1f
4 changed files with 11 additions and 7 deletions
@@ -19,6 +19,7 @@
**/
#include "wrap_ChainShape.h"
#include "wrap_Physics.h"
#include "Physics.h"
namespace love
@@ -60,7 +61,7 @@ namespace box2d
int w_ChainShape_getChildEdge(lua_State * L)
{
ChainShape * c = luax_checkchainshape(L, 1);
int index = luaL_checkint(L, 2);
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
EdgeShape * e = c->getChildEdge(index);
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
return 1;
@@ -77,8 +78,9 @@ namespace box2d
int w_ChainShape_getPoint(lua_State * L)
{
ChainShape * c = luax_checkchainshape(L, 1);
int index = luaL_checkint(L, 2);
b2Vec2 v = c->getPoint(index);
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
b2Vec2 v;
ASSERT_GUARD(v = c->getPoint(index);)
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
return 2;