Pack movie data in memory
[lsnes.git] / src / lua / movie.cpp
blob873ef6f65989edd07718457d0fbe7901816942a6
1 #include "core/lua-int.hpp"
2 #include "core/movie.hpp"
3 #include "core/moviedata.hpp"
5 namespace
7 function_ptr_luafun mcurframe("movie.currentframe", [](lua_State* LS, const std::string& fname) -> int {
8 auto& m = get_movie();
9 lua_pushnumber(LS, m.get_current_frame());
10 return 1;
11 });
13 function_ptr_luafun mfc("movie.framecount", [](lua_State* LS, const std::string& fname) -> int {
14 auto& m = get_movie();
15 lua_pushnumber(LS, m.get_frame_count());
16 return 1;
17 });
19 function_ptr_luafun mro("movie.readonly", [](lua_State* LS, const std::string& fname) -> int {
20 auto& m = get_movie();
21 lua_pushboolean(LS, m.readonly_mode() ? 1 : 0);
22 return 1;
23 });
25 function_ptr_luafun mrw("movie.readwrite", [](lua_State* LS, const std::string& fname) -> int {
26 auto& m = get_movie();
27 m.readonly_mode(false);
28 return 0;
29 });
31 function_ptr_luafun mfs("movie.frame_subframes", [](lua_State* LS, const std::string& fname) -> int {
32 uint64_t frame = get_numeric_argument<uint64_t>(LS, 1, "movie.frame_subframes");
33 auto& m = get_movie();
34 lua_pushnumber(LS, m.frame_subframes(frame));
35 return 1;
36 });
38 function_ptr_luafun mrs("movie.read_subframes", [](lua_State* LS, const std::string& fname) -> int {
39 uint64_t frame = get_numeric_argument<uint64_t>(LS, 1, "movie.frame_subframes");
40 uint64_t subframe = get_numeric_argument<uint64_t>(LS, 2, "movie.frame_subframes");
41 auto& m = get_movie();
42 controller_frame r = m.read_subframe(frame, subframe);
43 lua_newtable(LS);
45 lua_pushnumber(LS, 0);
46 lua_pushnumber(LS, r.sync() ? 1 : 0);
47 lua_settable(LS, -3);
48 lua_pushnumber(LS, 1);
49 lua_pushnumber(LS, r.reset() ? 1 : 0);
50 lua_settable(LS, -3);
51 lua_pushnumber(LS, 2);
52 lua_pushnumber(LS, r.delay().first);
53 lua_settable(LS, -3);
54 lua_pushnumber(LS, 3);
55 lua_pushnumber(LS, r.delay().second);
56 lua_settable(LS, -3);
58 for(size_t i = 0; i < MAX_BUTTONS; i++) {
59 lua_pushnumber(LS, i + 4);
60 lua_pushnumber(LS, r.axis2(i));
61 lua_settable(LS, -3);
63 return 1;
64 });
66 function_ptr_luafun rrc("movie.read_rtc", [](lua_State* LS, const std::string& fname) -> int {
67 lua_pushnumber(LS, our_movie.rtc_second);
68 lua_pushnumber(LS, our_movie.rtc_subsecond);
69 return 2;
70 });