Cleanup lua code by introducing lua::functions
[lsnes.git] / src / lua / subtitles.cpp
blob8ed201fb3e790a56d1d590ab682dff6893529184
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 lua::functions lua_subtitles(lua_func_misc, "subtitle", {
48 {"byindex", sub_byindex},
49 {"get", sub_get},
50 {"set", sub_set},
51 {"delete", sub_delete},
52 });