Refactor Lua support
[lsnes.git] / src / lua / subtitles.cpp
blob3a3094d31299766e8ab70186163427502a18d854
1 #include "lua/internal.hpp"
2 #include "core/subtitles.hpp"
4 namespace
6 function_ptr_luafun enumerate(LS, "subtitle.byindex", [](lua_state& L, const std::string& fname) -> int {
7 uint64_t n = L.get_numeric_argument<uint64_t>(1, fname.c_str());
8 uint64_t j = 0;
9 for(auto i : get_subtitles()) {
10 if(j == n) {
11 L.pushnumber(i.first);
12 L.pushnumber(i.second);
13 return 2;
15 j++;
17 return 0;
18 });
20 function_ptr_luafun sget(LS, "subtitle.get", [](lua_state& L, const std::string& fname) -> int {
21 uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
22 uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
23 std::string x = get_subtitle_for(frame, length);
24 L.pushstring(x.c_str());
25 return 1;
26 });
28 function_ptr_luafun sset(LS, "subtitle.set", [](lua_state& L, const std::string& fname) -> int {
29 uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
30 uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
31 std::string text = L.get_string(3, fname.c_str());
32 set_subtitle_for(frame, length, text);
33 return 0;
34 });
36 function_ptr_luafun sdel(LS, "subtitle.delete", [](lua_state& L, const std::string& fname) -> int {
37 uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
38 uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
39 set_subtitle_for(frame, length, "");
40 return 0;
41 });