mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Added GearJoint:getJoints (resolves issue #922.)
This commit is contained in:
@@ -51,10 +51,61 @@ int w_GearJoint_getRatio(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_GearJoint_getJoints(lua_State *L)
|
||||
{
|
||||
GearJoint *t = luax_checkgearjoint(L, 1);
|
||||
Joint *j1 = nullptr;
|
||||
Joint *j2 = nullptr;
|
||||
|
||||
luax_catchexcept(L, [&]() {
|
||||
j1 = t->getJointA();
|
||||
j2 = t->getJointB();
|
||||
});
|
||||
|
||||
auto pushjoint = [](lua_State *L, Joint *j) -> void
|
||||
{
|
||||
if (j == nullptr)
|
||||
return lua_pushnil(L);
|
||||
|
||||
switch (j->getType())
|
||||
{
|
||||
case Joint::JOINT_DISTANCE:
|
||||
return luax_pushtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, j);
|
||||
case Joint::JOINT_REVOLUTE:
|
||||
return luax_pushtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, j);
|
||||
case Joint::JOINT_PRISMATIC:
|
||||
return luax_pushtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, j);
|
||||
case Joint::JOINT_MOUSE:
|
||||
return luax_pushtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, j);
|
||||
case Joint::JOINT_PULLEY:
|
||||
return luax_pushtype(L, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, j);
|
||||
case Joint::JOINT_GEAR:
|
||||
return luax_pushtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, j);
|
||||
case Joint::JOINT_FRICTION:
|
||||
return luax_pushtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, j);
|
||||
case Joint::JOINT_WELD:
|
||||
return luax_pushtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, j);
|
||||
case Joint::JOINT_WHEEL:
|
||||
return luax_pushtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, j);
|
||||
case Joint::JOINT_ROPE:
|
||||
return luax_pushtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, j);
|
||||
case Joint::JOINT_MOTOR:
|
||||
return luax_pushtype(L, "MotorJoint", PHYSICS_MOTOR_JOINT_T, j);
|
||||
default:
|
||||
return lua_pushnil(L);
|
||||
}
|
||||
};
|
||||
|
||||
pushjoint(L, j1);
|
||||
pushjoint(L, j2);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "setRatio", w_GearJoint_setRatio },
|
||||
{ "getRatio", w_GearJoint_getRatio },
|
||||
{ "getJoints", w_GearJoint_getJoints },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getBodies", w_Joint_getBodies },
|
||||
|
||||
Reference in New Issue
Block a user