1 /**
2 * Copyright (c) 2006-2011 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_Shape.h"
22 #include <common/StringMap.h>
23 
24 namespace love
25 {
26 namespace physics
27 {
28 namespace box2d
29 {
luax_checkshape(lua_State * L,int idx)30 	Shape * luax_checkshape(lua_State * L, int idx)
31 	{
32 		return luax_checktype<Shape>(L, idx, "Shape", PHYSICS_SHAPE_T);
33 	}
34 
w_Shape_getType(lua_State * L)35 	int w_Shape_getType(lua_State * L)
36 	{
37 		Shape * t = luax_checkshape(L, 1);
38 		const char * type = "";
39 		Shape::getConstant(t->getType(), type);
40 		lua_pushstring(L, type);
41 		return 1;
42 	}
43 
w_Shape_setFriction(lua_State * L)44 	int w_Shape_setFriction(lua_State * L)
45 	{
46 		Shape * t = luax_checkshape(L, 1);
47 		float arg1 = (float)luaL_checknumber(L, 2);
48 		t->setFriction(arg1);
49 		return 0;
50 	}
51 
w_Shape_setRestitution(lua_State * L)52 	int w_Shape_setRestitution(lua_State * L)
53 	{
54 		Shape * t = luax_checkshape(L, 1);
55 		float arg1 = (float)luaL_checknumber(L, 2);
56 		t->setRestitution(arg1);
57 		return 0;
58 	}
59 
w_Shape_setDensity(lua_State * L)60 	int w_Shape_setDensity(lua_State * L)
61 	{
62 		Shape * t = luax_checkshape(L, 1);
63 		float arg1 = (float)luaL_checknumber(L, 2);
64 		t->setDensity(arg1);
65 		return 0;
66 	}
67 
w_Shape_setSensor(lua_State * L)68 	int w_Shape_setSensor(lua_State * L)
69 	{
70 		Shape * t = luax_checkshape(L, 1);
71 		bool arg1 = luax_toboolean(L, 2);
72 		t->setSensor(arg1);
73 		return 0;
74 	}
75 
w_Shape_getFriction(lua_State * L)76 	int w_Shape_getFriction(lua_State * L)
77 	{
78 		Shape * t = luax_checkshape(L, 1);
79 		lua_pushnumber(L, t->getFriction());
80 		return 1;
81 	}
82 
w_Shape_getRestitution(lua_State * L)83 	int w_Shape_getRestitution(lua_State * L)
84 	{
85 		Shape * t = luax_checkshape(L, 1);
86 		lua_pushnumber(L, t->getRestitution());
87 		return 1;
88 	}
89 
w_Shape_getDensity(lua_State * L)90 	int w_Shape_getDensity(lua_State * L)
91 	{
92 		Shape * t = luax_checkshape(L, 1);
93 		lua_pushnumber(L, t->getDensity());
94 		return 1;
95 	}
96 
w_Shape_isSensor(lua_State * L)97 	int w_Shape_isSensor(lua_State * L)
98 	{
99 		Shape * t = luax_checkshape(L, 1);
100 		luax_pushboolean(L, t->isSensor());
101 		return 1;
102 	}
103 
w_Shape_getBody(lua_State * L)104 	int w_Shape_getBody(lua_State * L)
105 	{
106 		Shape * t = luax_checkshape(L, 1);
107 		Body * body = t->getBody();
108 		if(body == 0)
109 			return 0;
110 		body->retain();
111 		luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
112 		return 1;
113 	}
114 
w_Shape_testPoint(lua_State * L)115 	int w_Shape_testPoint(lua_State * L)
116 	{
117 		Shape * t = luax_checkshape(L, 1);
118 		float x = (float)luaL_checknumber(L, 2);
119 		float y = (float)luaL_checknumber(L, 3);
120 		luax_pushboolean(L, t->testPoint(x, y));
121 		return 1;
122 	}
123 
w_Shape_testSegment(lua_State * L)124 	int w_Shape_testSegment(lua_State * L)
125 	{
126 		Shape * t = luax_checkshape(L, 1);
127 		lua_remove(L, 1);
128 		return t->testSegment(L);
129 	}
130 
w_Shape_setFilterData(lua_State * L)131 	int w_Shape_setFilterData(lua_State * L)
132 	{
133 		Shape * t = luax_checkshape(L, 1);
134 		int v[3];
135 		v[0] = luaL_checkint(L, 2);
136 		v[1] = luaL_checkint(L, 3);
137 		v[2] = luaL_checkint(L, 4);
138 		t->setFilterData(v);
139 		return 0;
140 	}
141 
w_Shape_getFilterData(lua_State * L)142 	int w_Shape_getFilterData(lua_State * L)
143 	{
144 		Shape * t = luax_checkshape(L, 1);
145 		int v[3];
146 		t->getFilterData(v);
147 		lua_pushinteger(L, v[0]);
148 		lua_pushinteger(L, v[1]);
149 		lua_pushinteger(L, v[2]);
150 		return 3;
151 	}
152 
w_Shape_setCategory(lua_State * L)153 	int w_Shape_setCategory(lua_State * L)
154 	{
155 		Shape * t = luax_checkshape(L, 1);
156 		lua_remove(L, 1);
157 		return t->setCategory(L);
158 	}
159 
w_Shape_getCategory(lua_State * L)160 	int w_Shape_getCategory(lua_State * L)
161 	{
162 		Shape * t = luax_checkshape(L, 1);
163 		lua_remove(L, 1);
164 		return t->getCategory(L);
165 	}
166 
w_Shape_setMask(lua_State * L)167 	int w_Shape_setMask(lua_State * L)
168 	{
169 		Shape * t = luax_checkshape(L, 1);
170 		lua_remove(L, 1);
171 		return t->setMask(L);
172 	}
173 
w_Shape_getMask(lua_State * L)174 	int w_Shape_getMask(lua_State * L)
175 	{
176 		Shape * t = luax_checkshape(L, 1);
177 		lua_remove(L, 1);
178 		return t->getMask(L);
179 	}
180 
w_Shape_setData(lua_State * L)181 	int w_Shape_setData(lua_State * L)
182 	{
183 		Shape * t = luax_checkshape(L, 1);
184 		lua_remove(L, 1);
185 		return t->setData(L);
186 	}
187 
w_Shape_getData(lua_State * L)188 	int w_Shape_getData(lua_State * L)
189 	{
190 		Shape * t = luax_checkshape(L, 1);
191 		lua_remove(L, 1);
192 		return t->getData(L);
193 	}
194 
w_Shape_getBoundingBox(lua_State * L)195 	int w_Shape_getBoundingBox(lua_State * L)
196 	{
197 		Shape * t = luax_checkshape(L, 1);
198 		lua_remove(L, 1);
199 		return t->getBoundingBox(L);
200 	}
201 
w_Shape_getGroupIndex(lua_State * L)202 	int w_Shape_getGroupIndex(lua_State * L)
203 	{
204 		Shape * t = luax_checkshape(L, 1);
205 		int i = t->getGroupIndex();
206 		lua_pushinteger(L, i);
207 		return 1;
208 	}
209 
w_Shape_setGroupIndex(lua_State * L)210 	int w_Shape_setGroupIndex(lua_State * L)
211 	{
212 		Shape * t = luax_checkshape(L, 1);
213 		int i = luaL_checkint(L, 2);
214 		t->setGroupIndex(i);
215 		return 0;
216 	}
217 
w_Shape_destroy(lua_State * L)218 	int w_Shape_destroy(lua_State * L)
219 	{
220 		Proxy * p = (Proxy *)lua_touserdata(L, 1);
221 		p->own = false;
222 
223 		Shape * t = (Shape *)p->data;
224 		t->release();
225 		return 0;
226 	}
227 
228 	static const luaL_Reg functions[] = {
229 		{ "getType", w_Shape_getType },
230 		{ "setFriction", w_Shape_setFriction },
231 		{ "setRestitution", w_Shape_setRestitution },
232 		{ "setDensity", w_Shape_setDensity },
233 		{ "setSensor", w_Shape_setSensor },
234 		{ "getFriction", w_Shape_getFriction },
235 		{ "getRestitution", w_Shape_getRestitution },
236 		{ "getDensity", w_Shape_getDensity },
237 		{ "getBody", w_Shape_getBody },
238 		{ "isSensor", w_Shape_isSensor },
239 		{ "testPoint", w_Shape_testPoint },
240 		{ "testSegment", w_Shape_testSegment },
241 		{ "setFilterData", w_Shape_setFilterData },
242 		{ "getFilterData", w_Shape_getFilterData },
243 		{ "setCategory", w_Shape_setCategory },
244 		{ "getCategory", w_Shape_getCategory },
245 		{ "setMask", w_Shape_setMask },
246 		{ "getMask", w_Shape_getMask },
247 		{ "setData", w_Shape_setData },
248 		{ "getData", w_Shape_getData },
249 		{ "getBoundingBox", w_Shape_getBoundingBox },
250 		{ "getGroupIndex", w_Shape_getGroupIndex },
251 		{ "setGroupIndex", w_Shape_setGroupIndex },
252 		{ "destroy", w_Shape_destroy },
253 		{ 0, 0 }
254 	};
255 
luaopen_shape(lua_State * L)256 	int luaopen_shape(lua_State * L)
257 	{
258 		return luax_register_type(L, "Shape", functions);
259 	}
260 
261 } // box2d
262 } // physics
263 } // love
264 
265