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_MouseJoint.h" |
22 | |
23 | namespace love |
24 | { |
25 | namespace physics |
26 | { |
27 | namespace box2d |
28 | { |
29 | |
30 | MouseJoint *luax_checkmousejoint(lua_State *L, int idx) |
31 | { |
32 | MouseJoint *j = luax_checktype<MouseJoint>(L, idx); |
33 | if (!j->isValid()) |
34 | luaL_error(L, "Attempt to use destroyed joint." ); |
35 | return j; |
36 | } |
37 | |
38 | int w_MouseJoint_setTarget(lua_State *L) |
39 | { |
40 | MouseJoint *t = luax_checkmousejoint(L, 1); |
41 | float x = (float)luaL_checknumber(L, 2); |
42 | float y = (float)luaL_checknumber(L, 3); |
43 | t->setTarget(x, y); |
44 | return 0; |
45 | } |
46 | |
47 | int w_MouseJoint_getTarget(lua_State *L) |
48 | { |
49 | MouseJoint *t = luax_checkmousejoint(L, 1); |
50 | lua_remove(L, 1); |
51 | return t->getTarget(L); |
52 | } |
53 | |
54 | int w_MouseJoint_setMaxForce(lua_State *L) |
55 | { |
56 | MouseJoint *t = luax_checkmousejoint(L, 1); |
57 | float f = (float)luaL_checknumber(L, 2); |
58 | t->setMaxForce(f); |
59 | return 0; |
60 | } |
61 | |
62 | int w_MouseJoint_getMaxForce(lua_State *L) |
63 | { |
64 | MouseJoint *t = luax_checkmousejoint(L, 1); |
65 | lua_pushnumber(L, t->getMaxForce()); |
66 | return 1; |
67 | } |
68 | |
69 | int w_MouseJoint_setFrequency(lua_State *L) |
70 | { |
71 | MouseJoint *t = luax_checkmousejoint(L, 1); |
72 | float arg1 = (float)luaL_checknumber(L, 2); |
73 | luax_catchexcept(L, [&]() { t->setFrequency(arg1); }); |
74 | return 0; |
75 | } |
76 | |
77 | int w_MouseJoint_getFrequency(lua_State *L) |
78 | { |
79 | MouseJoint *t = luax_checkmousejoint(L, 1); |
80 | lua_pushnumber(L, t->getFrequency()); |
81 | return 1; |
82 | } |
83 | |
84 | int w_MouseJoint_setDampingRatio(lua_State *L) |
85 | { |
86 | MouseJoint *t = luax_checkmousejoint(L, 1); |
87 | float arg1 = (float)luaL_checknumber(L, 2); |
88 | t->setDampingRatio(arg1); |
89 | return 0; |
90 | } |
91 | |
92 | int w_MouseJoint_getDampingRatio(lua_State *L) |
93 | { |
94 | MouseJoint *t = luax_checkmousejoint(L, 1); |
95 | lua_pushnumber(L, t->getDampingRatio()); |
96 | return 1; |
97 | } |
98 | |
99 | static const luaL_Reg w_MouseJoint_functions[] = |
100 | { |
101 | { "setTarget" , w_MouseJoint_setTarget }, |
102 | { "getTarget" , w_MouseJoint_getTarget }, |
103 | { "setMaxForce" , w_MouseJoint_setMaxForce }, |
104 | { "getMaxForce" , w_MouseJoint_getMaxForce }, |
105 | { "setFrequency" , w_MouseJoint_setFrequency }, |
106 | { "getFrequency" , w_MouseJoint_getFrequency }, |
107 | { "setDampingRatio" , w_MouseJoint_setDampingRatio }, |
108 | { "getDampingRatio" , w_MouseJoint_getDampingRatio }, |
109 | { 0, 0 } |
110 | }; |
111 | |
112 | extern "C" int luaopen_mousejoint(lua_State *L) |
113 | { |
114 | return luax_register_type(L, &MouseJoint::type, w_Joint_functions, w_MouseJoint_functions, nullptr); |
115 | } |
116 | |
117 | } // box2d |
118 | } // physics |
119 | } // love |
120 | |