1 /**
2 * Copyright (c) 2006-2016 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
w_newVideoStream(lua_State * L)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, VIDEO_VIDEO_STREAM_ID, stream);
49 stream->release();
50 return 1;
51 }
52
53 static const lua_CFunction types[] =
54 {
55 luaopen_videostream,
56 0
57 };
58
59 static const luaL_Reg functions[] =
60 {
61 { "newVideoStream", w_newVideoStream },
62 { 0, 0 }
63 };
64
luaopen_love_video(lua_State * L)65 extern "C" int luaopen_love_video(lua_State *L)
66 {
67 Video *instance = instance();
68 if (instance == nullptr)
69 {
70 luax_catchexcept(L, [&](){ instance = new love::video::theora::Video(); });
71 }
72 else
73 instance->retain();
74
75 WrappedModule w;
76 w.module = instance;
77 w.name = "video";
78 w.type = MODULE_ID;
79 w.functions = functions;
80 w.types = types;
81
82 return luax_register_module(L, w);
83 }
84
85 } // video
86 } // love
87