1/**
2 * Copyright (c) 2006-2023 LOVE Development Team
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 **/
20
21#include "wrap_GearJoint.h"
22#include "wrap_Physics.h"
23
24namespace love
25{
26namespace physics
27{
28namespace box2d
29{
30
31GearJoint *luax_checkgearjoint(lua_State *L, int idx)
32{
33 GearJoint *j = luax_checktype<GearJoint>(L, idx);
34 if (!j->isValid())
35 luaL_error(L, "Attempt to use destroyed joint.");
36 return j;
37}
38
39int w_GearJoint_setRatio(lua_State *L)
40{
41 GearJoint *t = luax_checkgearjoint(L, 1);
42 float arg1 = (float)luaL_checknumber(L, 2);
43 luax_catchexcept(L, [&](){ t->setRatio(arg1); });
44 return 0;
45}
46
47int w_GearJoint_getRatio(lua_State *L)
48{
49 GearJoint *t = luax_checkgearjoint(L, 1);
50 lua_pushnumber(L, t->getRatio());
51 return 1;
52}
53
54int w_GearJoint_getJoints(lua_State *L)
55{
56 GearJoint *t = luax_checkgearjoint(L, 1);
57 Joint *j1 = nullptr;
58 Joint *j2 = nullptr;
59
60 luax_catchexcept(L, [&]() {
61 j1 = t->getJointA();
62 j2 = t->getJointB();
63 });
64
65 luax_pushjoint(L, j1);
66 luax_pushjoint(L, j2);
67 return 2;
68}
69
70static const luaL_Reg w_GearJoint_functions[] =
71{
72 { "setRatio", w_GearJoint_setRatio },
73 { "getRatio", w_GearJoint_getRatio },
74 { "getJoints", w_GearJoint_getJoints },
75 { 0, 0 }
76};
77
78extern "C" int luaopen_gearjoint(lua_State *L)
79{
80 return luax_register_type(L, &GearJoint::type, w_Joint_functions, w_GearJoint_functions, nullptr);
81}
82
83} // box2d
84} // physics
85} // love
86