JSON-based controller descriptions
[lsnes.git] / src / lua / subtitles.cpp
blob520fb33bbe75ffed31697217e073952826c2d9d8
1 #include "lua/internal.hpp"
2 #include "core/subtitles.hpp"
4 namespace
6 function_ptr_luafun enumerate(lua_func_misc, "subtitle.byindex", [](lua_state& L, const std::string& fname)
7 -> int {
8 uint64_t n = L.get_numeric_argument<uint64_t>(1, fname.c_str());
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;
19 });
21 function_ptr_luafun sget(lua_func_misc, "subtitle.get", [](lua_state& L, const std::string& fname) -> int {
22 uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
23 uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
24 std::string x = get_subtitle_for(frame, length);
25 L.pushstring(x.c_str());
26 return 1;
27 });
29 function_ptr_luafun sset(lua_func_misc, "subtitle.set", [](lua_state& L, const std::string& fname) -> int {
30 uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
31 uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
32 std::string text = L.get_string(3, fname.c_str());
33 set_subtitle_for(frame, length, text);
34 return 0;
35 });
37 function_ptr_luafun sdel(lua_func_misc, "subtitle.delete", [](lua_state& L, const std::string& fname) -> int {
38 uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
39 uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
40 set_subtitle_for(frame, length, "");
41 return 0;
42 });