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 | // LOVE |
22 | #include "filesystem/wrap_Filesystem.h" |
23 | |
24 | #include "theora/Video.h" |
25 | #include "wrap_Video.h" |
26 | #include "wrap_VideoStream.h" |
27 | |
28 | namespace love |
29 | { |
30 | namespace video |
31 | { |
32 | |
33 | #define instance() (Module::getInstance<Video>(Module::M_VIDEO)) |
34 | |
35 | int w_newVideoStream(lua_State *L) |
36 | { |
37 | love::filesystem::File *file = love::filesystem::luax_getfile(L, 1); |
38 | |
39 | VideoStream *stream = nullptr; |
40 | luax_catchexcept(L, [&]() { |
41 | // Can't check if open for reading |
42 | if (!file->isOpen() && !file->open(love::filesystem::File::MODE_READ)) |
43 | luaL_error(L, "File is not open and cannot be opened" ); |
44 | |
45 | stream = instance()->newVideoStream(file); |
46 | }); |
47 | |
48 | luax_pushtype(L, stream); |
49 | stream->release(); |
50 | file->release(); |
51 | return 1; |
52 | } |
53 | |
54 | static const lua_CFunction types[] = |
55 | { |
56 | luaopen_videostream, |
57 | 0 |
58 | }; |
59 | |
60 | static const luaL_Reg functions[] = |
61 | { |
62 | { "newVideoStream" , w_newVideoStream }, |
63 | { 0, 0 } |
64 | }; |
65 | |
66 | extern "C" int luaopen_love_video(lua_State *L) |
67 | { |
68 | Video *instance = instance(); |
69 | if (instance == nullptr) |
70 | { |
71 | luax_catchexcept(L, [&](){ instance = new love::video::theora::Video(); }); |
72 | } |
73 | else |
74 | instance->retain(); |
75 | |
76 | WrappedModule w; |
77 | w.module = instance; |
78 | w.name = "video" ; |
79 | w.type = &Module::type; |
80 | w.functions = functions; |
81 | w.types = types; |
82 | |
83 | return luax_register_module(L, w); |
84 | } |
85 | |
86 | } // video |
87 | } // love |
88 | |