Refactor some generic reading/writing routines out of moviefile.cpp
[lsnes.git] / src / lua / subtitles.cpp
blob29bbc8759f3f149b2cb357f160062c5c3a168078
1 #include "lua/internal.hpp"
2 #include "core/subtitles.hpp"
4 namespace
6 int sub_byindex(lua::state& L, lua::parameters& P)
8 auto n = P.arg<uint64_t>();
9 uint64_t j = 0;
10 for(auto i : get_subtitles()) {
11 if(j == n) {
12 L.pushnumber(i.first);
13 L.pushnumber(i.second);
14 return 2;
16 j++;
18 return 0;
21 int sub_get(lua::state& L, lua::parameters& P)
23 auto frame = P.arg<uint64_t>();
24 auto length = P.arg<uint64_t>();
25 std::string x = get_subtitle_for(frame, length);
26 L.pushstring(x.c_str());
27 return 1;
30 int sub_set(lua::state& L, lua::parameters& P)
32 auto frame = P.arg<uint64_t>();
33 auto length = P.arg<uint64_t>();
34 std::string text = P.arg<std::string>();
35 set_subtitle_for(frame, length, text);
36 return 0;
39 int sub_delete(lua::state& L, lua::parameters& P)
41 auto frame = P.arg<uint64_t>();
42 auto length = P.arg<uint64_t>();
43 set_subtitle_for(frame, length, "");
44 return 0;
47 class lua_subtitles_dummy {};
48 lua::_class<lua_subtitles_dummy> lua_subtitles(lua_class_bind, "*subtitle", {
49 {"byindex", sub_byindex},
50 {"get", sub_get},
51 {"set", sub_set},
52 {"delete", sub_delete},
53 });