Since window is singleton anyway, get rid of window* parameters
[lsnes.git] / lua / settings.cpp
blob254d8e6efca5818f35b2dab4603c02a9df9325c9
1 #include "lua-int.hpp"
2 #include "settings.hpp"
4 namespace
6 class lua_settings_set : public lua_function
8 public:
9 lua_settings_set() : lua_function("settings.set") {}
10 int invoke(lua_State* LS)
12 std::string name = get_string_argument(LS, 1, fname.c_str());
13 std::string value = get_string_argument(LS, 2, fname.c_str());
14 try {
15 setting::set(name, value);
16 } catch(std::exception& e) {
17 lua_pushnil(LS);
18 lua_pushstring(LS, e.what());
19 return 2;
21 lua_pushboolean(LS, 1);
22 return 1;
24 } settings_set;
26 class lua_settings_get : public lua_function
28 public:
29 lua_settings_get() : lua_function("settings.get") {}
30 int invoke(lua_State* LS)
32 std::string name = get_string_argument(LS, 1, fname.c_str());
33 try {
34 if(!setting::is_set(name))
35 lua_pushboolean(LS, 0);
36 else {
37 std::string value = setting::get(name);
38 lua_pushlstring(LS, value.c_str(), value.length());
40 return 1;
41 } catch(std::exception& e) {
42 lua_pushnil(LS);
43 lua_pushstring(LS, e.what());
44 return 2;
47 } settings_get;
49 class lua_settings_blank : public lua_function
51 public:
52 lua_settings_blank() : lua_function("settings.blank") {}
53 int invoke(lua_State* LS)
55 std::string name = get_string_argument(LS, 1, fname.c_str());
56 try {
57 setting::blank(name);
58 lua_pushboolean(LS, 1);
59 return 1;
60 } catch(std::exception& e) {
61 lua_pushnil(LS);
62 lua_pushstring(LS, e.what());
63 return 2;
66 } settings_blank;
68 class lua_settings_is_set : public lua_function
70 public:
71 lua_settings_is_set() : lua_function("settings.is_set") {}
72 int invoke(lua_State* LS)
74 std::string name = get_string_argument(LS, 1, fname.c_str());
75 try {
76 bool x = setting::is_set(name);
77 lua_pushboolean(LS, x ? 1 : 0);
78 return 1;
79 } catch(std::exception& e) {
80 lua_pushnil(LS);
81 lua_pushstring(LS, e.what());
82 return 2;
85 } settings_is_set;