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_RevoluteJoint.h"
22#include "wrap_Physics.h"
23
24namespace love
25{
26namespace physics
27{
28namespace box2d
29{
30
31RevoluteJoint *luax_checkrevolutejoint(lua_State *L, int idx)
32{
33 RevoluteJoint *j = luax_checktype<RevoluteJoint>(L, idx);
34 if (!j->isValid())
35 luaL_error(L, "Attempt to use destroyed joint.");
36 return j;
37}
38
39int w_RevoluteJoint_getJointAngle(lua_State *L)
40{
41 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
42 lua_pushnumber(L, t->getJointAngle());
43 return 1;
44}
45
46int w_RevoluteJoint_getJointSpeed(lua_State *L)
47{
48 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
49 lua_pushnumber(L, t->getJointSpeed());
50 return 1;
51}
52
53int w_RevoluteJoint_setMotorEnabled(lua_State *L)
54{
55 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
56 bool arg1 = luax_checkboolean(L, 2);
57 t->setMotorEnabled(arg1);
58 return 0;
59}
60
61int w_RevoluteJoint_isMotorEnabled(lua_State *L)
62{
63 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
64 luax_pushboolean(L, t->isMotorEnabled());
65 return 1;
66}
67
68int w_RevoluteJoint_setMaxMotorTorque(lua_State *L)
69{
70 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
71 float arg1 = (float)luaL_checknumber(L, 2);
72 t->setMaxMotorTorque(arg1);
73 return 0;
74}
75
76int w_RevoluteJoint_setMotorSpeed(lua_State *L)
77{
78 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
79 float arg1 = (float)luaL_checknumber(L, 2);
80 t->setMotorSpeed(arg1);
81 return 0;
82}
83
84int w_RevoluteJoint_getMotorSpeed(lua_State *L)
85{
86 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
87 lua_pushnumber(L, t->getMotorSpeed());
88 return 1;
89}
90
91int w_RevoluteJoint_getMotorTorque(lua_State *L)
92{
93 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
94 float inv_dt = (float)luaL_checknumber(L, 2);
95 lua_pushnumber(L, t->getMotorTorque(inv_dt));
96 return 1;
97}
98
99int w_RevoluteJoint_getMaxMotorTorque(lua_State *L)
100{
101 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
102 lua_pushnumber(L, t->getMaxMotorTorque());
103 return 1;
104}
105
106int w_RevoluteJoint_setLimitsEnabled(lua_State *L)
107{
108 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
109 bool arg1 = luax_checkboolean(L, 2);
110 t->setLimitsEnabled(arg1);
111 return 0;
112}
113
114int w_RevoluteJoint_areLimitsEnabled(lua_State *L)
115{
116 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
117 luax_pushboolean(L, t->areLimitsEnabled());
118 return 1;
119}
120
121int w_RevoluteJoint_setUpperLimit(lua_State *L)
122{
123 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
124 float arg1 = (float)luaL_checknumber(L, 2);
125 luax_catchexcept(L, [&](){ t->setUpperLimit(arg1); });
126 return 0;
127}
128
129int w_RevoluteJoint_setLowerLimit(lua_State *L)
130{
131 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
132 float arg1 = (float)luaL_checknumber(L, 2);
133 luax_catchexcept(L, [&](){ t->setLowerLimit(arg1); });
134 return 0;
135}
136
137int w_RevoluteJoint_setLimits(lua_State *L)
138{
139 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
140 float arg1 = (float)luaL_checknumber(L, 2);
141 float arg2 = (float)luaL_checknumber(L, 3);
142 luax_catchexcept(L, [&](){ t->setLimits(arg1, arg2); });
143 return 0;
144}
145
146int w_RevoluteJoint_getLowerLimit(lua_State *L)
147{
148 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
149 lua_pushnumber(L, t->getLowerLimit());
150 return 1;
151}
152
153int w_RevoluteJoint_getUpperLimit(lua_State *L)
154{
155 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
156 lua_pushnumber(L, t->getUpperLimit());
157 return 1;
158}
159
160int w_RevoluteJoint_getLimits(lua_State *L)
161{
162 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
163 lua_remove(L, 1);
164 return t->getLimits(L);
165}
166
167int w_RevoluteJoint_getReferenceAngle(lua_State *L)
168{
169 RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
170 lua_pushnumber(L, t->getReferenceAngle());
171 return 1;
172}
173
174int w_RevoluteJoint_hasLimitsEnabled(lua_State *L)
175{
176 luax_markdeprecated(L, "RevoluteJoint:hasLimitsEnabled", API_METHOD, DEPRECATED_RENAMED, "RevoluteJoint:areLimitsEnabled");
177 return w_RevoluteJoint_areLimitsEnabled(L);
178}
179
180static const luaL_Reg w_RevoluteJoint_functions[] =
181{
182 { "getJointAngle", w_RevoluteJoint_getJointAngle },
183 { "getJointSpeed", w_RevoluteJoint_getJointSpeed },
184 { "setMotorEnabled", w_RevoluteJoint_setMotorEnabled },
185 { "isMotorEnabled", w_RevoluteJoint_isMotorEnabled },
186 { "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque },
187 { "setMotorSpeed", w_RevoluteJoint_setMotorSpeed },
188 { "getMotorSpeed", w_RevoluteJoint_getMotorSpeed },
189 { "getMotorTorque", w_RevoluteJoint_getMotorTorque },
190 { "getMaxMotorTorque", w_RevoluteJoint_getMaxMotorTorque },
191 { "setLimitsEnabled", w_RevoluteJoint_setLimitsEnabled },
192 { "areLimitsEnabled", w_RevoluteJoint_areLimitsEnabled },
193 { "setUpperLimit", w_RevoluteJoint_setUpperLimit },
194 { "setLowerLimit", w_RevoluteJoint_setLowerLimit },
195 { "setLimits", w_RevoluteJoint_setLimits },
196 { "getLowerLimit", w_RevoluteJoint_getLowerLimit },
197 { "getUpperLimit", w_RevoluteJoint_getUpperLimit },
198 { "getLimits", w_RevoluteJoint_getLimits },
199 { "getReferenceAngle", w_RevoluteJoint_getReferenceAngle },
200
201 // Deprecated
202 { "hasLimitsEnabled", w_RevoluteJoint_hasLimitsEnabled },
203
204 { 0, 0 }
205};
206
207extern "C" int luaopen_revolutejoint(lua_State *L)
208{
209 return luax_register_type(L, &RevoluteJoint::type, w_Joint_functions, w_RevoluteJoint_functions, nullptr);
210}
211
212} // box2d
213} // physics
214} // love
215