Use luaL_check/optinteger instead of luaL_check/optnumber when getting integer arguments to functions. Resolves issue #1251.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-07-16 12:17:50 -03:00
parent abcade9421
commit 34ebe18f14
30 changed files with 127 additions and 127 deletions
+2 -2
View File
@@ -280,7 +280,7 @@ int Fixture::rayCast(lua_State *L) const
float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
float maxFraction = (float)luaL_checknumber(L, 5);
int childIndex = (int) luaL_optnumber(L, 6, 1) - 1; // Convert from 1-based index
int childIndex = (int) luaL_optinteger(L, 6, 1) - 1; // Convert from 1-based index
b2RayCastInput input;
input.p1.Set(p1x, p1y);
input.p2.Set(p2x, p2y);
@@ -296,7 +296,7 @@ int Fixture::rayCast(lua_State *L) const
int Fixture::getBoundingBox(lua_State *L) const
{
int childIndex = (int) luaL_optnumber(L, 1, 1) - 1; // Convert from 1-based index
int childIndex = (int) luaL_optinteger(L, 1, 1) - 1; // Convert from 1-based index
b2AABB box;
luax_catchexcept(L, [&]() { box = fixture->GetAABB(childIndex); });
box = Physics::scaleUp(box);
+9 -9
View File
@@ -31,7 +31,7 @@ namespace physics
namespace box2d
{
int Physics::meter = Physics::DEFAULT_METER;
float Physics::meter = Physics::DEFAULT_METER;
const char *Physics::getName() const
{
@@ -323,37 +323,37 @@ int Physics::getDistance(lua_State *L)
return 5;
}
void Physics::setMeter(int scale)
void Physics::setMeter(float scale)
{
if (scale < 1) throw love::Exception("Physics error: invalid meter");
Physics::meter = scale;
}
int Physics::getMeter()
float Physics::getMeter()
{
return meter;
}
void Physics::scaleDown(float &x, float &y)
{
x /= (float)meter;
y /= (float)meter;
x /= meter;
y /= meter;
}
void Physics::scaleUp(float &x, float &y)
{
x *= (float)meter;
y *= (float)meter;
x *= meter;
y *= meter;
}
float Physics::scaleDown(float f)
{
return f/(float)meter;
return f/meter;
}
float Physics::scaleUp(float f)
{
return f*(float)meter;
return f*meter;
}
b2Vec2 Physics::scaleDown(const b2Vec2 &v)
+3 -3
View File
@@ -292,13 +292,13 @@ public:
* Sets the number of pixels in one meter.
* @param scale The number of pixels in one meter. (1m ~= 3.3ft).
**/
static void setMeter(int scale);
static void setMeter(float scale);
/**
* Gets the number of pixels in one meter.
* @return The number of pixels in one meter. (1m ~= 3.3ft).
**/
static int getMeter();
static float getMeter();
/**
* Scales a value down according to the current meter in pixels.
@@ -359,7 +359,7 @@ public:
private:
// The length of one meter in pixels.
static int meter;
static float meter;
}; // Physics
} // box2d
+2 -2
View File
@@ -105,7 +105,7 @@ int Shape::rayCast(lua_State *L) const
float x = Physics::scaleDown((float)luaL_checknumber(L, 6));
float y = Physics::scaleDown((float)luaL_checknumber(L, 7));
float r = (float)luaL_checknumber(L, 8);
int childIndex = (int) luaL_optnumber(L, 9, 1) - 1; // Convert from 1-based index
int childIndex = (int) luaL_optinteger(L, 9, 1) - 1; // Convert from 1-based index
b2RayCastInput input;
input.p1.Set(p1x, p1y);
input.p2.Set(p2x, p2y);
@@ -125,7 +125,7 @@ int Shape::computeAABB(lua_State *L) const
float x = Physics::scaleDown((float)luaL_checknumber(L, 1));
float y = Physics::scaleDown((float)luaL_checknumber(L, 2));
float r = (float)luaL_checknumber(L, 3);
int childIndex = (int) luaL_optnumber(L, 4, 1) - 1; // Convert from 1-based index
int childIndex = (int) luaL_optinteger(L, 4, 1) - 1; // Convert from 1-based index
b2Transform transform(b2Vec2(x, y), b2Rot(r));
b2AABB box;
shape->ComputeAABB(&box, transform, childIndex);
@@ -65,7 +65,7 @@ int w_ChainShape_setPreviousVertex(lua_State *L)
int w_ChainShape_getChildEdge(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
int index = (int) luaL_checkinteger(L, 2) - 1; // Convert from 1-based index
EdgeShape *e = 0;
luax_catchexcept(L, [&](){ e = c->getChildEdge(index); });
luax_pushtype(L, e);
@@ -84,7 +84,7 @@ int w_ChainShape_getVertexCount(lua_State *L)
int w_ChainShape_getPoint(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
int index = (int) luaL_checkinteger(L, 2) - 1; // Convert from 1-based index
b2Vec2 v;
luax_catchexcept(L, [&](){ v = c->getPoint(index); });
lua_pushnumber(L, v.x);
+4 -4
View File
@@ -164,9 +164,9 @@ int w_Fixture_setFilterData(lua_State *L)
{
Fixture *t = luax_checkfixture(L, 1);
int v[3];
v[0] = (int) luaL_checknumber(L, 2);
v[1] = (int) luaL_checknumber(L, 3);
v[2] = (int) luaL_checknumber(L, 4);
v[0] = (int) luaL_checkinteger(L, 2);
v[1] = (int) luaL_checkinteger(L, 3);
v[2] = (int) luaL_checkinteger(L, 4);
t->setFilterData(v);
return 0;
}
@@ -249,7 +249,7 @@ int w_Fixture_getGroupIndex(lua_State *L)
int w_Fixture_setGroupIndex(lua_State *L)
{
Fixture *t = luax_checkfixture(L, 1);
int i = (int) luaL_checknumber(L, 2);
int i = (int) luaL_checkinteger(L, 2);
t->setGroupIndex(i);
return 0;
}
+1 -1
View File
@@ -471,7 +471,7 @@ int w_getDistance(lua_State *L)
int w_setMeter(lua_State *L)
{
int arg1 = (int) luaL_checknumber(L, 1);
float arg1 = (float) luaL_checknumber(L, 1);
luax_catchexcept(L, [&](){ Physics::setMeter(arg1); });
return 0;
+2 -2
View File
@@ -47,8 +47,8 @@ int w_World_update(lua_State *L)
luax_catchexcept(L, [&](){ t->update(dt); });
else
{
int velocityiterations = (int) luaL_checknumber(L, 3);
int positioniterations = (int) luaL_checknumber(L, 4);
int velocityiterations = (int) luaL_checkinteger(L, 3);
int positioniterations = (int) luaL_checkinteger(L, 4);
luax_catchexcept(L, [&](){ t->update(dt, velocityiterations, positioniterations); });
}