Add start paused option
[lsnes.git] / src / lua / settings.cpp
blobc0d3edbf8c051cf70c393d3c2a6a281cdf3ce33d
1 #include "lua/internal.hpp"
2 #include "core/settings.hpp"
4 namespace
6 function_ptr_luafun ss("settings.set", [](lua_State* LS, const std::string& fname) -> int {
7 std::string name = get_string_argument(LS, 1, fname.c_str());
8 std::string value = get_string_argument(LS, 2, fname.c_str());
9 try {
10 setting::set(name, value);
11 } catch(std::exception& e) {
12 lua_pushnil(LS);
13 lua_pushstring(LS, e.what());
14 return 2;
16 lua_pushboolean(LS, 1);
17 return 1;
18 });
20 function_ptr_luafun sg("settings.get", [](lua_State* LS, const std::string& fname) -> int {
21 std::string name = get_string_argument(LS, 1, fname.c_str());
22 try {
23 if(!setting::is_set(name))
24 lua_pushboolean(LS, 0);
25 else {
26 std::string value = setting::get(name);
27 lua_pushlstring(LS, value.c_str(), value.length());
29 return 1;
30 } catch(std::exception& e) {
31 lua_pushnil(LS);
32 lua_pushstring(LS, e.what());
33 return 2;
35 });
37 function_ptr_luafun sb("settings.blank", [](lua_State* LS, const std::string& fname) -> int {
38 std::string name = get_string_argument(LS, 1, fname.c_str());
39 try {
40 setting::blank(name);
41 lua_pushboolean(LS, 1);
42 return 1;
43 } catch(std::exception& e) {
44 lua_pushnil(LS);
45 lua_pushstring(LS, e.what());
46 return 2;
48 });
50 function_ptr_luafun si("settings.is_set", [](lua_State* LS, const std::string& fname) -> int {
51 std::string name = get_string_argument(LS, 1, fname.c_str());
52 try {
53 bool x = setting::is_set(name);
54 lua_pushboolean(LS, x ? 1 : 0);
55 return 1;
56 } catch(std::exception& e) {
57 lua_pushnil(LS);
58 lua_pushstring(LS, e.what());
59 return 2;
61 });