| 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_PrismaticJoint.h" |
| 22 | #include "wrap_Physics.h" |
| 23 | |
| 24 | namespace love |
| 25 | { |
| 26 | namespace physics |
| 27 | { |
| 28 | namespace box2d |
| 29 | { |
| 30 | |
| 31 | PrismaticJoint *luax_checkprismaticjoint(lua_State *L, int idx) |
| 32 | { |
| 33 | PrismaticJoint *j = luax_checktype<PrismaticJoint>(L, idx); |
| 34 | if (!j->isValid()) |
| 35 | luaL_error(L, "Attempt to use destroyed joint." ); |
| 36 | return j; |
| 37 | } |
| 38 | |
| 39 | int w_PrismaticJoint_getJointTranslation(lua_State *L) |
| 40 | { |
| 41 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 42 | lua_pushnumber(L, t->getJointTranslation()); |
| 43 | return 1; |
| 44 | } |
| 45 | |
| 46 | int w_PrismaticJoint_getJointSpeed(lua_State *L) |
| 47 | { |
| 48 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 49 | lua_pushnumber(L, t->getJointSpeed()); |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | int w_PrismaticJoint_setMotorEnabled(lua_State *L) |
| 54 | { |
| 55 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 56 | bool arg1 = luax_checkboolean(L, 2); |
| 57 | t->setMotorEnabled(arg1); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | int w_PrismaticJoint_isMotorEnabled(lua_State *L) |
| 62 | { |
| 63 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 64 | luax_pushboolean(L, t->isMotorEnabled()); |
| 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | int w_PrismaticJoint_setMaxMotorForce(lua_State *L) |
| 69 | { |
| 70 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 71 | float arg1 = (float)luaL_checknumber(L, 2); |
| 72 | t->setMaxMotorForce(arg1); |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | int w_PrismaticJoint_setMotorSpeed(lua_State *L) |
| 77 | { |
| 78 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 79 | float arg1 = (float)luaL_checknumber(L, 2); |
| 80 | t->setMotorSpeed(arg1); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | int w_PrismaticJoint_getMotorSpeed(lua_State *L) |
| 85 | { |
| 86 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 87 | lua_pushnumber(L, t->getMotorSpeed()); |
| 88 | return 1; |
| 89 | } |
| 90 | |
| 91 | int w_PrismaticJoint_getMotorForce(lua_State *L) |
| 92 | { |
| 93 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 94 | float inv_dt = (float)luaL_checknumber(L, 2); |
| 95 | lua_pushnumber(L, t->getMotorForce(inv_dt)); |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | int w_PrismaticJoint_getMaxMotorForce(lua_State *L) |
| 100 | { |
| 101 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 102 | lua_pushnumber(L, t->getMaxMotorForce()); |
| 103 | return 1; |
| 104 | } |
| 105 | |
| 106 | int w_PrismaticJoint_setLimitsEnabled(lua_State *L) |
| 107 | { |
| 108 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 109 | bool arg1 = luax_checkboolean(L, 2); |
| 110 | t->setLimitsEnabled(arg1); |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | int w_PrismaticJoint_areLimitsEnabled(lua_State *L) |
| 115 | { |
| 116 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 117 | luax_pushboolean(L, t->areLimitsEnabled()); |
| 118 | return 1; |
| 119 | } |
| 120 | |
| 121 | int w_PrismaticJoint_setUpperLimit(lua_State *L) |
| 122 | { |
| 123 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 124 | float arg1 = (float)luaL_checknumber(L, 2); |
| 125 | luax_catchexcept(L, [&](){ t->setUpperLimit(arg1); }); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | int w_PrismaticJoint_setLowerLimit(lua_State *L) |
| 130 | { |
| 131 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 132 | float arg1 = (float)luaL_checknumber(L, 2); |
| 133 | luax_catchexcept(L, [&](){ t->setLowerLimit(arg1); }); |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | int w_PrismaticJoint_setLimits(lua_State *L) |
| 138 | { |
| 139 | PrismaticJoint *t = luax_checkprismaticjoint(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 | |
| 146 | int w_PrismaticJoint_getLowerLimit(lua_State *L) |
| 147 | { |
| 148 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 149 | lua_pushnumber(L, t->getLowerLimit()); |
| 150 | return 1; |
| 151 | } |
| 152 | |
| 153 | int w_PrismaticJoint_getUpperLimit(lua_State *L) |
| 154 | { |
| 155 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 156 | lua_pushnumber(L, t->getUpperLimit()); |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | int w_PrismaticJoint_getLimits(lua_State *L) |
| 161 | { |
| 162 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 163 | lua_remove(L, 1); |
| 164 | return t->getLimits(L); |
| 165 | } |
| 166 | |
| 167 | int w_PrismaticJoint_getAxis(lua_State *L) |
| 168 | { |
| 169 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 170 | lua_remove(L, 1); |
| 171 | return t->getAxis(L); |
| 172 | } |
| 173 | |
| 174 | int w_PrismaticJoint_getReferenceAngle(lua_State *L) |
| 175 | { |
| 176 | PrismaticJoint *t = luax_checkprismaticjoint(L, 1); |
| 177 | lua_pushnumber(L, t->getReferenceAngle()); |
| 178 | return 1; |
| 179 | } |
| 180 | |
| 181 | int w_PrismaticJoint_hasLimitsEnabled(lua_State *L) |
| 182 | { |
| 183 | luax_markdeprecated(L, "PrismaticJoint:hasLimitsEnabled" , API_METHOD, DEPRECATED_RENAMED, "PrismaticJoint:areLimitsEnabled" ); |
| 184 | return w_PrismaticJoint_areLimitsEnabled(L); |
| 185 | } |
| 186 | |
| 187 | static const luaL_Reg w_PrismaticJoint_functions[] = |
| 188 | { |
| 189 | { "getJointTranslation" , w_PrismaticJoint_getJointTranslation }, |
| 190 | { "getJointSpeed" , w_PrismaticJoint_getJointSpeed }, |
| 191 | { "setMotorEnabled" , w_PrismaticJoint_setMotorEnabled }, |
| 192 | { "isMotorEnabled" , w_PrismaticJoint_isMotorEnabled }, |
| 193 | { "setMaxMotorForce" , w_PrismaticJoint_setMaxMotorForce }, |
| 194 | { "setMotorSpeed" , w_PrismaticJoint_setMotorSpeed }, |
| 195 | { "getMotorSpeed" , w_PrismaticJoint_getMotorSpeed }, |
| 196 | { "getMotorForce" , w_PrismaticJoint_getMotorForce }, |
| 197 | { "getMaxMotorForce" , w_PrismaticJoint_getMaxMotorForce }, |
| 198 | { "setLimitsEnabled" , w_PrismaticJoint_setLimitsEnabled }, |
| 199 | { "areLimitsEnabled" , w_PrismaticJoint_areLimitsEnabled }, |
| 200 | { "setUpperLimit" , w_PrismaticJoint_setUpperLimit }, |
| 201 | { "setLowerLimit" , w_PrismaticJoint_setLowerLimit }, |
| 202 | { "setLimits" , w_PrismaticJoint_setLimits }, |
| 203 | { "getLowerLimit" , w_PrismaticJoint_getLowerLimit }, |
| 204 | { "getUpperLimit" , w_PrismaticJoint_getUpperLimit }, |
| 205 | { "getLimits" , w_PrismaticJoint_getLimits }, |
| 206 | { "getAxis" , w_PrismaticJoint_getAxis }, |
| 207 | { "getReferenceAngle" , w_PrismaticJoint_getReferenceAngle }, |
| 208 | |
| 209 | // Deprecated |
| 210 | { "hasLimitsEnabled" , w_PrismaticJoint_hasLimitsEnabled }, |
| 211 | |
| 212 | { 0, 0 } |
| 213 | }; |
| 214 | |
| 215 | extern "C" int luaopen_prismaticjoint(lua_State *L) |
| 216 | { |
| 217 | return luax_register_type(L, &PrismaticJoint::type, w_Joint_functions, w_PrismaticJoint_functions, nullptr); |
| 218 | } |
| 219 | |
| 220 | } // box2d |
| 221 | } // physics |
| 222 | } // love |
| 223 | |