| 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_EdgeShape.h" |
| 22 | |
| 23 | namespace love |
| 24 | { |
| 25 | namespace physics |
| 26 | { |
| 27 | namespace box2d |
| 28 | { |
| 29 | |
| 30 | EdgeShape *luax_checkedgeshape(lua_State *L, int idx) |
| 31 | { |
| 32 | return luax_checktype<EdgeShape>(L, idx); |
| 33 | } |
| 34 | |
| 35 | int w_EdgeShape_setNextVertex(lua_State *L) |
| 36 | { |
| 37 | EdgeShape *t = luax_checkedgeshape(L, 1); |
| 38 | if (lua_isnoneornil(L, 2)) |
| 39 | t->setNextVertex(); |
| 40 | else |
| 41 | { |
| 42 | float x = (float)luaL_checknumber(L, 2); |
| 43 | float y = (float)luaL_checknumber(L, 3); |
| 44 | t->setNextVertex(x, y); |
| 45 | } |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | int w_EdgeShape_setPreviousVertex(lua_State *L) |
| 50 | { |
| 51 | EdgeShape *t = luax_checkedgeshape(L, 1); |
| 52 | if (lua_isnoneornil(L, 2)) |
| 53 | t->setPreviousVertex(); |
| 54 | else |
| 55 | { |
| 56 | float x = (float)luaL_checknumber(L, 2); |
| 57 | float y = (float)luaL_checknumber(L, 3); |
| 58 | t->setPreviousVertex(x, y); |
| 59 | } |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int w_EdgeShape_getNextVertex(lua_State *L) |
| 64 | { |
| 65 | EdgeShape *t = luax_checkedgeshape(L, 1); |
| 66 | float x, y; |
| 67 | if (t->getNextVertex(x, y)) |
| 68 | { |
| 69 | lua_pushnumber(L, x); |
| 70 | lua_pushnumber(L, y); |
| 71 | return 2; |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | int w_EdgeShape_getPreviousVertex(lua_State *L) |
| 77 | { |
| 78 | EdgeShape *t = luax_checkedgeshape(L, 1); |
| 79 | float x, y; |
| 80 | if (t->getPreviousVertex(x, y)) |
| 81 | { |
| 82 | lua_pushnumber(L, x); |
| 83 | lua_pushnumber(L, y); |
| 84 | return 2; |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | int w_EdgeShape_getPoints(lua_State *L) |
| 90 | { |
| 91 | EdgeShape *t = luax_checkedgeshape(L, 1); |
| 92 | lua_remove(L, 1); |
| 93 | return t->getPoints(L); |
| 94 | } |
| 95 | |
| 96 | static const luaL_Reg w_EdgeShape_functions[] = |
| 97 | { |
| 98 | { "setNextVertex" , w_EdgeShape_setNextVertex }, |
| 99 | { "setPreviousVertex" , w_EdgeShape_setPreviousVertex }, |
| 100 | { "getNextVertex" , w_EdgeShape_getNextVertex }, |
| 101 | { "getPreviousVertex" , w_EdgeShape_getPreviousVertex }, |
| 102 | { "getPoints" , w_EdgeShape_getPoints }, |
| 103 | { 0, 0 } |
| 104 | }; |
| 105 | |
| 106 | extern "C" int luaopen_edgeshape(lua_State *L) |
| 107 | { |
| 108 | return luax_register_type(L, &EdgeShape::type, w_Shape_functions, w_EdgeShape_functions, nullptr); |
| 109 | } |
| 110 | |
| 111 | } // box2d |
| 112 | } // physics |
| 113 | } // love |
| 114 | |