mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Automatically deduce the type in luax_pushtype, if possible
--HG-- branch : dynamiccore2
This commit is contained in:
@@ -435,7 +435,7 @@ int Body::getFixtureList(lua_State *L) const
|
||||
Fixture *fixture = (Fixture *)Memoizer::find(f);
|
||||
if (!fixture)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
luax_pushtype(L, Fixture::type, fixture);
|
||||
luax_pushtype(L, fixture);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
@@ -483,7 +483,7 @@ int Body::getContactList(lua_State *L) const
|
||||
else
|
||||
contact->retain();
|
||||
|
||||
luax_pushtype(L, Contact::type, contact);
|
||||
luax_pushtype(L, contact);
|
||||
contact->release();
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
|
||||
@@ -146,7 +146,7 @@ int Physics::newPolygonShape(lua_State *L)
|
||||
}
|
||||
|
||||
PolygonShape *p = new PolygonShape(s);
|
||||
luax_pushtype(L, PolygonShape::type, p);
|
||||
luax_pushtype(L, p);
|
||||
p->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -208,7 +208,7 @@ int Physics::newChainShape(lua_State *L)
|
||||
delete[] vecs;
|
||||
|
||||
ChainShape *c = new ChainShape(s);
|
||||
luax_pushtype(L, ChainShape::type, c);
|
||||
luax_pushtype(L, c);
|
||||
c->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
{
|
||||
Fixture *a = (Fixture *)Memoizer::find(contact->GetFixtureA());
|
||||
if (a != nullptr)
|
||||
luax_pushtype(L, Fixture::type, a);
|
||||
luax_pushtype(L, a);
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
@@ -68,7 +68,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
{
|
||||
Fixture *b = (Fixture *)Memoizer::find(contact->GetFixtureB());
|
||||
if (b != nullptr)
|
||||
luax_pushtype(L, Fixture::type, b);
|
||||
luax_pushtype(L, b);
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
@@ -79,7 +79,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
else
|
||||
cobj->retain();
|
||||
|
||||
luax_pushtype(L, Contact::type, cobj);
|
||||
luax_pushtype(L, cobj);
|
||||
cobj->release();
|
||||
|
||||
int args = 3;
|
||||
@@ -130,8 +130,8 @@ bool World::ContactFilter::process(Fixture *a, Fixture *b)
|
||||
if (ref != nullptr && L != nullptr)
|
||||
{
|
||||
ref->push(L);
|
||||
luax_pushtype(L, Fixture::type, a);
|
||||
luax_pushtype(L, Fixture::type, b);
|
||||
luax_pushtype(L, a);
|
||||
luax_pushtype(L, b);
|
||||
lua_call(L, 2, 1);
|
||||
return luax_toboolean(L, -1);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ bool World::QueryCallback::ReportFixture(b2Fixture *fixture)
|
||||
Fixture *f = (Fixture *)Memoizer::find(fixture);
|
||||
if (!f)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
luax_pushtype(L, Fixture::type, f);
|
||||
luax_pushtype(L, f);
|
||||
lua_call(L, 1, 1);
|
||||
bool cont = luax_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
@@ -186,7 +186,7 @@ float32 World::RayCastCallback::ReportFixture(b2Fixture *fixture, const b2Vec2 &
|
||||
Fixture *f = (Fixture *)Memoizer::find(fixture);
|
||||
if (!f)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
luax_pushtype(L, Fixture::type, f);
|
||||
luax_pushtype(L, f);
|
||||
b2Vec2 scaledPoint = Physics::scaleUp(point);
|
||||
lua_pushnumber(L, scaledPoint.x);
|
||||
lua_pushnumber(L, scaledPoint.y);
|
||||
@@ -475,7 +475,7 @@ int World::getBodyList(lua_State *L) const
|
||||
Body *body = (Body *)Memoizer::find(b);
|
||||
if (!body)
|
||||
throw love::Exception("A body has escaped Memoizer!");
|
||||
luax_pushtype(L, Body::type, body);
|
||||
luax_pushtype(L, body);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
@@ -493,7 +493,7 @@ int World::getJointList(lua_State *L) const
|
||||
if (!j) break;
|
||||
Joint *joint = (Joint *)Memoizer::find(j);
|
||||
if (!joint) throw love::Exception("A joint has escaped Memoizer!");
|
||||
luax_pushtype(L, Joint::type, joint);
|
||||
luax_pushtype(L, joint);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
@@ -514,7 +514,7 @@ int World::getContactList(lua_State *L) const
|
||||
contact = new Contact(c);
|
||||
else
|
||||
contact->retain();
|
||||
luax_pushtype(L, Contact::type, contact);
|
||||
luax_pushtype(L, contact);
|
||||
contact->release();
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
|
||||
@@ -526,7 +526,7 @@ int w_Body_getWorld(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
World *world = t->getWorld();
|
||||
luax_pushtype(L, World::type, world);
|
||||
luax_pushtype(L, world);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ int w_ChainShape_getChildEdge(lua_State *L)
|
||||
int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
|
||||
EdgeShape *e = 0;
|
||||
luax_catchexcept(L, [&](){ e = c->getChildEdge(index); });
|
||||
luax_pushtype(L, EdgeShape::type, e);
|
||||
luax_pushtype(L, e);
|
||||
e->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -146,8 +146,8 @@ int w_Contact_getFixtures(lua_State *L)
|
||||
Fixture *b = nullptr;
|
||||
luax_catchexcept(L, [&](){ t->getFixtures(a, b); });
|
||||
|
||||
luax_pushtype(L, Fixture::type, a);
|
||||
luax_pushtype(L, Fixture::type, b);
|
||||
luax_pushtype(L, a);
|
||||
luax_pushtype(L, b);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ int w_Fixture_getBody(lua_State *L)
|
||||
Body *body = t->getBody();
|
||||
if (body == 0)
|
||||
return 0;
|
||||
luax_pushtype(L, Body::type, body);
|
||||
luax_pushtype(L, body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -124,19 +124,19 @@ int w_Fixture_getShape(lua_State *L)
|
||||
switch (shape->getType())
|
||||
{
|
||||
case Shape::SHAPE_EDGE:
|
||||
luax_pushtype(L, EdgeShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
break;
|
||||
case Shape::SHAPE_CHAIN:
|
||||
luax_pushtype(L, ChainShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
break;
|
||||
case Shape::SHAPE_CIRCLE:
|
||||
luax_pushtype(L, CircleShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
break;
|
||||
case Shape::SHAPE_POLYGON:
|
||||
luax_pushtype(L, PolygonShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
break;
|
||||
default:
|
||||
luax_pushtype(L, Shape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -103,8 +103,8 @@ int w_Joint_getBodies(lua_State *L)
|
||||
b2 = t->getBodyB();
|
||||
});
|
||||
|
||||
luax_pushtype(L, Body::type, b1);
|
||||
luax_pushtype(L, Body::type, b2);
|
||||
luax_pushtype(L, b1);
|
||||
luax_pushtype(L, b2);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ int w_newWorld(lua_State *L)
|
||||
|
||||
World *w;
|
||||
luax_catchexcept(L, [&](){ w = instance()->newWorld(gx, gy, sleep); });
|
||||
luax_pushtype(L, World::type, w);
|
||||
luax_pushtype(L, w);
|
||||
w->release();
|
||||
|
||||
return 1;
|
||||
@@ -78,7 +78,7 @@ int w_newBody(lua_State *L)
|
||||
|
||||
Body *body;
|
||||
luax_catchexcept(L, [&](){ body = instance()->newBody(world, x, y, btype); });
|
||||
luax_pushtype(L, Body::type, body);
|
||||
luax_pushtype(L, body);
|
||||
body->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ int w_newFixture(lua_State *L)
|
||||
float density = (float)luaL_optnumber(L, 3, 1.0f);
|
||||
Fixture *fixture;
|
||||
luax_catchexcept(L, [&](){ fixture = instance()->newFixture(body, shape, density); });
|
||||
luax_pushtype(L, Fixture::type, fixture);
|
||||
luax_pushtype(L, fixture);
|
||||
fixture->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ int w_newCircleShape(lua_State *L)
|
||||
float radius = (float)luaL_checknumber(L, 1);
|
||||
CircleShape *shape;
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newCircleShape(radius); });
|
||||
luax_pushtype(L, CircleShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ int w_newCircleShape(lua_State *L)
|
||||
float radius = (float)luaL_checknumber(L, 3);
|
||||
CircleShape *shape;
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newCircleShape(x, y, radius); });
|
||||
luax_pushtype(L, CircleShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ int w_newRectangleShape(lua_State *L)
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
PolygonShape *shape;
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newRectangleShape(w, h); });
|
||||
luax_pushtype(L, PolygonShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ int w_newRectangleShape(lua_State *L)
|
||||
float angle = (float)luaL_optnumber(L, 5, 0);
|
||||
PolygonShape *shape;
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newRectangleShape(x, y, w, h, angle); });
|
||||
luax_pushtype(L, PolygonShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ int w_newEdgeShape(lua_State *L)
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
EdgeShape *shape;
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newEdgeShape(x1, y1, x2, y2); });
|
||||
luax_pushtype(L, EdgeShape::type, shape);
|
||||
luax_pushtype(L, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ int w_newDistanceJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, DistanceJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ int w_newMouseJoint(lua_State *L)
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
MouseJoint *j;
|
||||
luax_catchexcept(L, [&](){ j = instance()->newMouseJoint(body, x, y); });
|
||||
luax_pushtype(L, MouseJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -237,7 +237,7 @@ int w_newRevoluteJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newRevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected, referenceAngle);
|
||||
});
|
||||
luax_pushtype(L, RevoluteJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -272,7 +272,7 @@ int w_newPrismaticJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected, referenceAngle);
|
||||
});
|
||||
luax_pushtype(L, PrismaticJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -296,7 +296,7 @@ int w_newPulleyJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, PulleyJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -312,7 +312,7 @@ int w_newGearJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newGearJoint(joint1, joint2, ratio, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, GearJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ int w_newFrictionJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, FrictionJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -372,7 +372,7 @@ int w_newWeldJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected, referenceAngle);
|
||||
});
|
||||
luax_pushtype(L, WeldJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -406,7 +406,7 @@ int w_newWheelJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, WheelJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -425,7 +425,7 @@ int w_newRopeJoint(lua_State *L)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, RopeJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
@@ -447,7 +447,7 @@ int w_newMotorJoint(lua_State *L)
|
||||
{
|
||||
luax_catchexcept(L, [&](){ j = instance()->newMotorJoint(body1, body2); });
|
||||
}
|
||||
luax_pushtype(L, MotorJoint::type, j);
|
||||
luax_pushtype(L, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user