| 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_Video.h" |
| 22 | |
| 23 | // Shove the wrap_Video.lua code directly into a raw string literal. |
| 24 | static const char video_lua[] = |
| 25 | #include "wrap_Video.lua" |
| 26 | ; |
| 27 | |
| 28 | namespace love |
| 29 | { |
| 30 | namespace graphics |
| 31 | { |
| 32 | |
| 33 | Video *luax_checkvideo(lua_State *L, int idx) |
| 34 | { |
| 35 | return luax_checktype<Video>(L, idx); |
| 36 | } |
| 37 | |
| 38 | int w_Video_getStream(lua_State *L) |
| 39 | { |
| 40 | Video *video = luax_checkvideo(L, 1); |
| 41 | luax_pushtype(L, video->getStream()); |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | int w_Video_getSource(lua_State *L) |
| 46 | { |
| 47 | Video *video = luax_checkvideo(L, 1); |
| 48 | auto source = video->getSource(); |
| 49 | if (source) |
| 50 | luax_pushtype(L, video->getSource()); |
| 51 | else |
| 52 | lua_pushnil(L); |
| 53 | return 1; |
| 54 | } |
| 55 | |
| 56 | int w_Video_setSource(lua_State *L) |
| 57 | { |
| 58 | Video *video = luax_checkvideo(L, 1); |
| 59 | if (lua_isnoneornil(L, 2)) |
| 60 | video->setSource(nullptr); |
| 61 | else |
| 62 | { |
| 63 | auto source = luax_checktype<love::audio::Source>(L, 2); |
| 64 | video->setSource(source); |
| 65 | } |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | int w_Video_getWidth(lua_State *L) |
| 70 | { |
| 71 | Video *video = luax_checkvideo(L, 1); |
| 72 | lua_pushnumber(L, video->getWidth()); |
| 73 | return 1; |
| 74 | } |
| 75 | |
| 76 | int w_Video_getHeight(lua_State *L) |
| 77 | { |
| 78 | Video *video = luax_checkvideo(L, 1); |
| 79 | lua_pushnumber(L, video->getHeight()); |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | int w_Video_getDimensions(lua_State *L) |
| 84 | { |
| 85 | Video *video = luax_checkvideo(L, 1); |
| 86 | lua_pushnumber(L, video->getWidth()); |
| 87 | lua_pushnumber(L, video->getHeight()); |
| 88 | return 2; |
| 89 | } |
| 90 | |
| 91 | int w_Video_getPixelWidth(lua_State *L) |
| 92 | { |
| 93 | Video *video = luax_checkvideo(L, 1); |
| 94 | lua_pushnumber(L, video->getPixelWidth()); |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | int w_Video_getPixelHeight(lua_State *L) |
| 99 | { |
| 100 | Video *video = luax_checkvideo(L, 1); |
| 101 | lua_pushnumber(L, video->getPixelHeight()); |
| 102 | return 1; |
| 103 | } |
| 104 | |
| 105 | int w_Video_getPixelDimensions(lua_State *L) |
| 106 | { |
| 107 | Video *video = luax_checkvideo(L, 1); |
| 108 | lua_pushnumber(L, video->getPixelWidth()); |
| 109 | lua_pushnumber(L, video->getPixelHeight()); |
| 110 | return 2; |
| 111 | } |
| 112 | |
| 113 | int w_Video_setFilter(lua_State *L) |
| 114 | { |
| 115 | Video *video = luax_checkvideo(L, 1); |
| 116 | Texture::Filter f = video->getFilter(); |
| 117 | |
| 118 | const char *minstr = luaL_checkstring(L, 2); |
| 119 | const char *magstr = luaL_optstring(L, 3, minstr); |
| 120 | |
| 121 | if (!Texture::getConstant(minstr, f.min)) |
| 122 | return luax_enumerror(L, "filter mode" , Texture::getConstants(f.min), minstr); |
| 123 | if (!Texture::getConstant(magstr, f.mag)) |
| 124 | return luax_enumerror(L, "filter mode" , Texture::getConstants(f.mag), magstr); |
| 125 | |
| 126 | f.anisotropy = (float) luaL_optnumber(L, 4, 1.0); |
| 127 | |
| 128 | luax_catchexcept(L, [&](){ video->setFilter(f); }); |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | int w_Video_getFilter(lua_State *L) |
| 133 | { |
| 134 | Video *video = luax_checkvideo(L, 1); |
| 135 | const Texture::Filter f = video->getFilter(); |
| 136 | |
| 137 | const char *minstr = nullptr; |
| 138 | const char *magstr = nullptr; |
| 139 | |
| 140 | if (!Texture::getConstant(f.min, minstr)) |
| 141 | return luaL_error(L, "Unknown filter mode." ); |
| 142 | if (!Texture::getConstant(f.mag, magstr)) |
| 143 | return luaL_error(L, "Unknown filter mode." ); |
| 144 | |
| 145 | lua_pushstring(L, minstr); |
| 146 | lua_pushstring(L, magstr); |
| 147 | lua_pushnumber(L, f.anisotropy); |
| 148 | return 3; |
| 149 | } |
| 150 | |
| 151 | static const luaL_Reg functions[] = |
| 152 | { |
| 153 | { "getStream" , w_Video_getStream }, |
| 154 | { "getSource" , w_Video_getSource }, |
| 155 | { "_setSource" , w_Video_setSource }, |
| 156 | { "getWidth" , w_Video_getWidth }, |
| 157 | { "getHeight" , w_Video_getHeight }, |
| 158 | { "getDimensions" , w_Video_getDimensions }, |
| 159 | { "getPixelWidth" , w_Video_getPixelWidth }, |
| 160 | { "getPixelHeight" , w_Video_getPixelHeight }, |
| 161 | { "getPixelDimensions" , w_Video_getPixelDimensions }, |
| 162 | { "setFilter" , w_Video_setFilter }, |
| 163 | { "getFilter" , w_Video_getFilter }, |
| 164 | { 0, 0 } |
| 165 | }; |
| 166 | |
| 167 | int luaopen_video(lua_State *L) |
| 168 | { |
| 169 | int ret = luax_register_type(L, &Video::type, functions, nullptr); |
| 170 | |
| 171 | luaL_loadbuffer(L, video_lua, sizeof(video_lua), "=[love \"Video.lua\"]" ); |
| 172 | luax_gettypemetatable(L, Video::type); |
| 173 | lua_call(L, 1, 0); |
| 174 | |
| 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | } // graphics |
| 179 | } // love |
| 180 | |