mirror of
https://github.com/love2d/love.git
synced 2026-08-21 13:09:56 +02:00
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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user