]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_settings.h
C++11 cleanup on constructors (#6000)
[dragonfireclient.git] / src / script / lua_api / l_settings.h
1 /*
2 Minetest
3 Copyright (C) 2013 PilzAdam <pilzadam@minetest.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef L_SETTINGS_H_
21 #define L_SETTINGS_H_
22
23 #include "lua_api/l_base.h"
24
25 class Settings;
26
27 class LuaSettings : public ModApiBase
28 {
29 private:
30         static const char className[];
31         static const luaL_Reg methods[];
32
33         // garbage collector
34         static int gc_object(lua_State *L);
35
36         // get(self, key) -> value
37         static int l_get(lua_State *L);
38
39         // get_bool(self, key) -> boolean
40         static int l_get_bool(lua_State *L);
41
42         // set(self, key, value)
43         static int l_set(lua_State *L);
44
45         // set_bool(self, key, value)
46         static int l_set_bool(lua_State *L);
47
48         // remove(self, key) -> success
49         static int l_remove(lua_State *L);
50
51         // get_names(self) -> {key1, ...}
52         static int l_get_names(lua_State *L);
53
54         // write(self) -> success
55         static int l_write(lua_State *L);
56
57         // to_table(self) -> {[key1]=value1,...}
58         static int l_to_table(lua_State *L);
59
60         Settings *m_settings = nullptr;
61         std::string m_filename;
62         bool m_is_own_settings = false;
63         bool m_write_allowed = true;
64
65 public:
66         LuaSettings(Settings *settings, const std::string &filename);
67         LuaSettings(const std::string &filename, bool write_allowed);
68         ~LuaSettings();
69
70         static void create(lua_State *L, Settings *settings, const std::string &filename);
71
72         // LuaSettings(filename)
73         // Creates a LuaSettings and leaves it on top of the stack
74         static int create_object(lua_State *L);
75
76         static LuaSettings *checkobject(lua_State *L, int narg);
77
78         static void Register(lua_State *L);
79 };
80
81 #endif