Map box2d asserts to love::Exception and catch them in constructors

Should be added to other functions commonly failing sometime.
This commit is contained in:
Bart van Strien
2011-06-08 21:44:21 +02:00
parent 3460bf918c
commit 6e28c49a20
2 changed files with 57 additions and 36 deletions
@@ -19,13 +19,13 @@
#ifndef B2_SETTINGS_H
#define B2_SETTINGS_H
#include <assert.h>
//#include <common/Exception.h>
//#include <assert.h>
#include <common/Exception.h>
#include <cmath>
#define B2_NOT_USED(x) x
#define b2Assert(A) assert(A)
//#define b2Assert(A) {if(!(A)) throw love::Exception("Box2D error: " #A);}
//#define b2Assert(A) assert(A)
#define b2Assert(A) {if(!(A)) throw love::Exception(#A);}
// need to include NDS jtypes.h instead of
@@ -66,6 +66,8 @@ namespace box2d
Body * body = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
int top = lua_gettop(L);
try
{
if(top == 2)
{
float radius = (float)luaL_checknumber(L, 2);
@@ -85,12 +87,19 @@ namespace box2d
else
return luaL_error(L, "Incorrect number of parameters");
}
catch (love::Exception e)
{
return luaL_error(L, "Box2D error: %s", e.what());
}
}
int w_newRectangleShape(lua_State * L)
{
Body * body = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
int top = lua_gettop(L);
try
{
if(top == 3)
{
float w = (float)luaL_checknumber(L, 2);
@@ -113,11 +122,23 @@ namespace box2d
else
return luaL_error(L, "Incorrect number of parameters");
}
catch (love::Exception e)
{
return luaL_error(L, "Box2D error: %s", e.what());
}
}
int w_newPolygonShape(lua_State * L)
{
try
{
return instance->newPolygonShape(L);
}
catch (love::Exception e)
{
return luaL_error(L, "Box2D error: %s", e.what());
}
}
int w_newDistanceJoint(lua_State * L)
{